I am using c++ 98 (as that is what is installed on the university server). I am trying to save an output to a file. The filename has to be dice_N.dat where N is the number of rolls of the dice, which I have called n_trials. I have tried following the suggestions on inserting int variable in file name. When using the second suggestion I get the output N.dat. Here the snippet of my code which tries to do this:
ostringstream fileNameStream("dice_");
fileNameStream << n_trials << ".dat";
string fileName = fileNameStream.str();
ofstream myfile;
myfile.open(fileName.c_str());
I can't use to_string
as this is not supported in c++ 98