-
string Q
I have a recurring code section that writes data files to a specific directory.
../../Data_x_r/PR2/Scheme_2_TVD_1/. Can i specify as a string "'constant" so that I only change it once rather going through every instance and changing it. Hope I am clear
Code:
stringstream ss;
string file_name;
ss << "surface_z_" << Hori_L/Diameter << "D_PR_" << P_r << "Pe_Ma_" << Mach << "_Time_" << timer1 << ".dat";
file_name = ss.str();
ofstream plotdata(("../../Data_x_r/PR2/Scheme_2_TVD_1/"+file_name).c_str());
Shuo
-
Code:
const string outfile = "../../Data_x_r/PR2/Scheme_2_TVD_1/";
Edit: outfile is a bad name, outdir would be better.
-
Code:
string file_path = "../../Data_x_r/PR2/Scheme_2_TVD_1/"+file_name;
?
-
But to answer your question maybe:
I'm not sure that a constant string is completely appropriate, expecially if you have to loop these statements repeatedly. I know that open()'s fist argument is passed as a constant, so you probably have nothing to worry about (in terms of the data changing) in this context.