I\'m trying to write a program in C++, which creates some files (.txt) and writes down the result in them. The problem is that an amount of these files is not fixed at the begin
I use the following code for this, you may find this useful.
std::ofstream ofile;
for(unsigned int n = 0; ; ++ n)
{
std::string fname = std::string("log") + std::tostring(n) << + std::string(".txt");
std::ifstream ifile;
ifile.open(fname.c_str());
if(ifile.is_open())
{
}
else
{
ofile.open(fname.c_str());
break;
}
ifile.close();
}
if(!ofile.is_open())
{
return -1;
}
ofile.close();