file name
Hello to all,
I have a function here receive some vector's and I put the vector content into a file, like:
1 2 3 4 5 6 7 8 9 10
|
void forwardMg (std::vector<std::string> vect_hold)
{
myfile.open ("/home/user/Desktop/file.txt");
size_t vsize = vect_hold.size();
for (size_t n=0; n<vsize; n++){
myfile << vect_hold[n] << '\n';
}
myfile.close();
}
| |
I need, each time I call this function, that the name of the file that is created is different like file1.txt and file2.txt, etc.
Can someone advise me.
Regards,
CMarco
You could simply use concatenation to achieve this. Watch:
1 2 3 4 5 6 7 8
|
#include <sstream>
for (int i = 0; i < 10; ++i) {
std::stringstream stream;
stream << i;
myfile.open("/home/user/Desktop/file" + stream + ".txt");
stream.clear();
}
| |
Make sense? Increase i every iteration and put it into a std::stringstream, so you can concatenate with it.
Thanks
Topic archived. No new replies allowed.