Мне нужно создать файл журнала. Я не знаю, какие ошибки нужно помещать в файл журнала.
У меня есть следующий код (но я не знаю, почему не записывает в конец файла)
log.cpp
#include "log.h"
#include <ctime>
#include <iostream>
using namespace std;
Log::Log(char* filename) {
//ofstream m_stream(filename);
m_stream.open(filename);
}
В test.cpp у меня есть pLOg-> Write (c). Я не понимаю, почему переписывает файл и почему не пишет в нем.
void Log::Write(char* logline)
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
m_stream.seekp (0, ios::end);
while ((m_stream.eof())){}
{
m_stream <<"current time: "<< asctime (timeinfo) <<" "<< logline << endl;
}
}
Log::~Log(){
m_stream.close();
}
log.h
#include <fstream>
using namespace std;
class Log {
public:
Log(char* filename);
~Log();
void Write(char* logline);
private:
ofstream m_stream;
};