wtorek, 30 marca 2021

Save time to file (C/C++)

 #include <sys/time.h>

#include <iostream>

#include <unistd.h>

#include <time.h>

#include <string.h>

#include <fstream>

using namespace std;


class print_Time

{

private:

char print_Day[64];

char print_Year[64];

struct tm* loctime;

struct timeval gettime;

public:

print_Time()

{

gettimeofday(&gettime,NULL);

loctime=localtime(&gettime.tv_sec);

}

void save_Day(string file_Name)

{

strftime(print_Day,sizeof(print_Day),"%D-%m-%y %S:%M:%H",loctime);

ofstream my_File;

my_File.open(file_Name.c_str());

my_File<<print_Day;

my_File.close();

}

void save_Year(string file_Name)

{

strftime(print_Year,sizeof(print_Year),"%Y-%m-%d %H:%M:%S",loctime);

ofstream my_File;

my_File.open(file_Name.c_str());

my_File<<print_Year;

my_File.close();

}

};




int main(int argc, char **argv)

{

string dataD="dataDay.txt";

string dataY="dataYear.txt";

print_Time *p_Time=new class print_Time;

p_Time->save_Day(dataD);

p_Time->save_Year(dataY);

delete [] p_Time;

return 0;

}


Brak komentarzy:

Prześlij komentarz