Wednesday, 28 August 2013

Making a sequential list of files

Making a sequential list of files

I have been stuck on a problem for a while now and can't seem to find an
answer. I'm trying to create multiple files with the same name but a
different number at the end each time, I have attempted this at first just
by using
int seq_number = 1;
while (seq_number < 10)
{
ofstream fsave;
fsave.open("filename" + seq_number + ".txt");
fsave << "blablabla";
fsave.close();
seq_number = seq_number + 1;
}
But that gives me a very strange result where the letters get jumbled up,
I'm not sure how that works but I know it doesn't.
I've looked online and found stringstream or sstream, and tried with that,
but it keeps giving me errors too,
string filename;
filename = "character";
ostringstream s;
s << filename << seq_number;
filename(s.str());
fsave.open(filename + ".txt");
fsave << "blabla"
fsave.close(;)
but i keep getting an error:
no match for call to `(std::string) (std::basic_string, std::allocator >)'
I'm not sure how string stream works exactly so im working off of
instinct, but i would appreciate any way this is possible, and honestly I
think I would prefer doing it without sstream, but i need a way to get an
int and str together and save a filename that is a string. unless you know
a better way ;) thanks guys

No comments:

Post a Comment