I just don't want to repeat the content, the content sometimes is a lot.
Then you can have a vector of ofstream
s and perform the "writing" inside a loop.
That should do!!! Thanks, ne555! Thanks, minomic!
Another simple example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <fstream>
int main(int argc, char const *argv[])
{
int N = 2;
std::ofstream streams[N];
streams[0].open ("test1.dat");
streams[1].open ("test2.dat");
for(int i = 0; i < N; ++i) {
streams[i] << "Content" << std::endl;
}
for(int i = 0; i < N; ++i) {
streams[i].close();
}
return 0;
}
|
Last edited on