writing a file with a variable as a filename?
I can get a file to write to a specific file name using the following code.
Code:
ofstream outfile("name.dat");
outfile << username << endl;
outfile << age << endl;
outfile.close();
simple enough.
But instead of it writing to a file "name.dat"
I would like it to write to a file that is equivalent to the username.
I've tried a few thigns like the following
Code:
ofstream outfile(username + ".dat");
outfile << username << endl;
outfile << age << endl;
outfile.close();
But apparantly that doesn't follow the fstream rules. I've experimented with a whole bunch of other failed options apparantly I'm going about this the wrong way. Can someone give me some insight that might point me in the right direction.
Muchly appreciated.