I seem to be having some issues trying to finish up my C++ Program and would appriciate some help.
At the end of my program I need it too output to a text file. I've tried various methods using fstream and ofstream to check if the file exists and if it does, make a new one, although I've had no luck.
Heres where Im at so far, but if "output.txt" exists then it just deletes whats in it and doesnt create anything, but doesnt crash.
...
ofstream output;
int fileIncrement = 0;
bool validFile = false;
cout << "Saving File.." << endl;
output.open("output.txt");
while (!validFile)
{
if (output.good()) // does exist
{
fileIncrement++;
output.open(to_string(fileIncrement) + "output.txt");
}
else
{
myVectors.outputVectors(output);
validFile = true;
}
}
Thank you.