#include <iostream>
#include <ctime>
#include <fstream>
usingnamespace std;
void difc();
int m;
struct tm * timeinfos;
ofstream dif("e:\\dif.txt");
int main()
{
cout<<"press 1 for Dif:";
int x;
cin>>x;
if(x==1){
void difc();
return 0;
}
time_t rawtime;
time (&rawtime);
timeinfos = localtime (&rawtime);
cout<<"Current local time and date:"<<asctime(timeinfos)<<endl;
dif.open("e:\\dif.txt");
dif<<asctime(timeinfos);
dif.close();
}
void difc(){
time_t rawtime;
struct tm * now;
double secs;
time (&rawtime);
now = localtime (&rawtime);
fstream dif;
dif.open("e:\\dif.txt");
dif>>timeinfos->tm_hour;
dif>>timeinfos->tm_min;
dif>>timeinfos->tm_sec;
dif.close();
secs=difftime(now,mktime(&timeinfos));
cout<<secs;
}
in this program first want u to get an int if is 1 first will get current time and will go for txt file and opened and take time that saves last time
in line 42 i Get if int is not 1 will get current time and save it into txt file for later that you want get difftime between this and another time.(difftime that i say i mean only Seconds)
what im doing wrong?
It looks to me like you are calling mktime incorrectly.
Try correcting the second parameter by declaring struct tm timeinfos; instead of struct tm * timeinfos;
This will fix line 42, but break lines 38-40 until you change the ->s to .s on those lines.