當我int main()
其唯一目的是將數據輸出到文件中下測試ofstream
,那麼我可以沒有問題編譯。但是,當我在int main(...)
中有其他參數時,出現以下錯誤。如何在int main(...)
中聲明ofstream
?什麼應該是C++中int main的參數/聲明?
error: ‘ofstream’ was not declared in this scope
error: expected ‘;’ before ‘phi_file’
error: ‘phi_file’ was not declared in this scope
int main(int argc, char** args, double phi_fcn())
{
int frame ;
double *x, *y, *vx, *vy ;
x = new double[N_POINTS] ; y = new double[N_POINTS] ;
vx = new double[N_POINTS] ; vy = new double[N_POINTS] ;
char file_name[255] ;
printf("The number of particles is N_POINTS=%d;\n",N_POINTS) ;
printf("the box size is L=%4.2f; ",L) ;
printf("the interaction radius is a=%17.16f;\n",a) ;
printf("the radius of repulsion is R_R=%17.16f;\n",R_R) ;
printf("the radius of repulsion squared is R_R_SQUARED=%17.16f;\n",R_R_SQUARED) ;
printf("the radius of orientation is R_O=%17.16f;\n",R_O) ;
printf("the radius of orientation squared is R_O_SQUARED=%17.16f;\n",R_O_SQUARED) ;
// generate initial distribution of particles
icond_uniform(x,y,vx,vy,N_POINTS) ;
// draw the first picture
sprintf(file_name, "tga_files/out%04d.tga", 0);
drawPicture(file_name,RES_X,RES_Y,x,y,N_POINTS);
ofstream phi_file;//create a phi_file to write to
phi_file.open("phi_per_timestep.dat");***
// time stepping loop
for (frame=1; frame<N_FRAMES; frame++)
{
interact_all(x,y,vx,vy,N_POINTS);
advect(x,y,vx,vy,N_POINTS);
// output data into graphics file
sprintf(file_name, "tga_files/out%04d.tga", frame);
drawPicture(file_name,RES_X,RES_Y,x,y,N_POINTS);
phi_file << phi_fcn();
}
phi_file.close();
return 0;
}
爲什麼你'main'功能有其他參數?你包括什麼標題?你有沒有使用指令? – 2011-03-11 20:40:05
的#include 的#include 的#include 的#include 的#include 「tga.h」 的#include 的#include 的#include 的#include 的#include –
flora
2011-03-11 21:31:17
上述所有都包括。如果我沒有int main()中的double phi_fcn(),那麼會出現另一個錯誤,說phi_fcn()沒有聲明。一旦我添加它,該錯誤消失。 – flora 2011-03-11 21:31:49