#include <iostream>
#include <fstream>
#include <string.h>
#include <time.h>
#include <unistd.h>
using namespace std;
class time_File
{
private:
char* nameF;
int timeS;
time_t now_T;
public:
time_File(char* fileName, int sleepTime)
{
nameF=fileName;
timeS=sleepTime;
}
void Save()
{
int i;
fstream file(nameF,ios::out);
if (file.good())
{
for(i=0;i<timeS;i++)
{
now_T=time(NULL);
char *temp_File=asctime(localtime(&now_T));
file<<temp_File;
file.flush();
sleep(1);
}
file.close();
}
}
};
int main(int argc, char **argv)
{
time_File Timer("date.txt",7);
Timer.Save();
return 0;
}
Result: date.txt
Tue Nov 30 08:32:10 2021
Tue Nov 30 08:32:11 2021
Tue Nov 30 08:32:12 2021
Tue Nov 30 08:32:13 2021
Tue Nov 30 08:32:14 2021
Tue Nov 30 08:32:15 2021
Tue Nov 30 08:32:16 2021
Brak komentarzy:
Prześlij komentarz