How to change the txt ofstream automatically

Hey hey!

I'm working in a Rugby Tournament Management program in c++ and I wanted to save info from Seasons on txt files.

In the beggining I was doing ofstream like this:

ofstream fout("seasons.txt");
for(unsigned int i = 0; i < all_seasons.size(); i++)


My problem is that I wanted to automatically save the info in txt with the season year name.

for this i would have to do something like this, which gives me an error:

string test = "x" // to be changed with the season year
ofstream fout("seasons.txt");
for(unsigned int i = 0; i < all_seasons.size(); i++)


Does anyone know how to do this?



Last edited on
Do you mean like this?
1
2
string test = "x";
ofstream fout ( ( "season_"+test+".txt").c_str() );

It would create a file called "season_x.txt"
taths it :D

hope it works ;)

checking it out
Topic archived. No new replies allowed.