niedziela, 21 lutego 2016

Creating new file with timestamp in class C++.




#include <iostream>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>


using namespace std;

class New_File_with_timestamp
{
private:
time_t time_now;
char *time1;
char *path;
int file;
mode_t authorization;
size_t length;
public:
New_File_with_timestamp(char *tekst)
{
time_now=time(NULL);

authorization=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
path=tekst;
file=open(path,O_WRONLY | O_EXCL | O_CREAT, authorization);
time1=asctime(localtime(&time_now));
length=strlen(time1);
}
void Write()
{
write(file,time1,length);
close(file);
}
};

int main(int argc, char** argv)
{
New_File_with_timestamp NFWT("my_file_with_stamp");
NFWT.Write();

return 0;
}

Brak komentarzy:

Prześlij komentarz