I have a program that needs to create a file titled "timestamp.txt" and accomplishes this with:
ofstream outstream;
outstream.open("timestamp.txt", ios::app);
I need this file to be created once and have the initial value of 1. This number then needs to be incremented.
When the file is created, I can use:
outstream << "1";
to put the number 1 in the file. How can I do this one time at the creation of the file so that the value is not reset every time the program runs?
I then need to store this value of 1 in local variable time. This can be done at the first execution of the program, but on following executions, how can I pull the numeric value out as an integer and store it in variable time?
Following the execution of the beginning of my program, a local variable time is incremented and must then be put back into timestamp.txt.
ofstream outstream;
outstream.open("timestamp.txt", ios::in);
outstream << time;
Edit: I am very inexperienced with C++. I am pleased to find that I come off knowing more about io than I truly do. I am comfortable with the interworking of ofstream much, much more than I am with ifstream. Using:
ifstream instream("timestamp.txt");
if (instream.good())
{
getline(instream, timestamp);
time = timestamp;
}
I can retrieve the string value for the first line in timestamp.txt, but I need this value as an integer not as a string.