当我测试其唯一目的是将数据输出到文件ofstream
中int main()
时,我可以毫无问题地编译。但是,当我在里面有其他参数时int main(...)
,会出现以下错误。我如何ofstream
申报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;
}