czwartek, 18 listopada 2021

Sleep() example C++

 #include <iostream>

#include <fcntl.h>

#include <fstream>

#include <stdio.h>

#include <string.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <time.h>

#include <unistd.h>

using namespace std;




class time_in_File

{

private:

char* now_Time();

char* file_Name;

int sl;

public:

char* write_Time();

time_in_File(char* name, int m_Sleep);

void Save();

};


char* time_in_File::now_Time()

{

char *n_Time;

time_t act;

act=time(NULL);

n_Time=asctime(localtime(&act));

return n_Time;

}

char* time_in_File::write_Time()

{

return now_Time();

}

time_in_File::time_in_File(char* name, int m_Sleep)

{

file_Name=name;

sl=m_Sleep;

}

void time_in_File::Save()

{

int i;

fstream my_File(file_Name,ios::out);

if(my_File.good())

{

for(i=0;i<sl;i++)

{

my_File<<write_Time()<<"\n";

sleep(sl);

}

my_File.close();

}

}


int main(int argc, char **argv)

{

char* n="Example.txt";

int s=5;

time_in_File my_Class(n,s);

my_Class.Save();

return 0;

}

RESULT File: Example.txt

Thu Nov 18 18:26:52 2021

Thu Nov 18 18:26:57 2021

Thu Nov 18 18:27:02 2021

Thu Nov 18 18:27:07 2021

Thu Nov 18 18:27:12 2021

Brak komentarzy:

Prześlij komentarz