Hello there, this is a program to count the miliseconds from the program starts and also write it in a file and next time when it open to read that number, count the time opened and write it, to infinity, something like the steam play time. And the problem is at line 43, i dont know how to write that number (named 'tt') to a txt file, how to fix it? Thanks in advance!
#include <iostream>
#include <stdio.h>
#include <sys\timeb.h>
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
struct timeb start, end;
int fws, sev, pct, tt;
int diff;
ftime(&start);
while(fws == 0)
{
cout<<"Type '6' to close the program safely: ";
cin >> sev;
if(sev == 6)
{
cout<<"Closing the program with safe state"<<endl;
fws += 1;
}
else
{
cout<<"Try again!"<<endl;
}
}
ftime(&end);
diff = (int) (1000.0 * (end.time - start.time) + (end.millitm - start.millitm));
cout<<"Operation took "<<diff<<" milliseconds."<<endl;
cout<<"Adding to the counting ..."<<endl;
std::ifstream myfile("elt.txt", std::ofstream::trunc);
if (myfile.is_open())
{
while ( getline (myfile,pct) )
{
cout << "Counted time already: " << pct;
}
tt = pct + diff;
myfile << tt;
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
pct = proceded counted time (Must read from file) //Idk i like to do weird cuted name for all the variables
diff = time when program opened
tt = total time (Must overwrite when program close on an text file)
EDIT: I see this one has another error, at line 42, why? i dont understand too much that :P but i wanted there to read the number from file and also display it.