로그 파일을 만들어야합니다. 나는 어떤 오류가 로그 파일에 넣어야하는지 모른다. 나는 다음과 같은 코드가 있습니다 (그러나 파일의 끝을 writting되지 않는 이유 나도 몰라) 내가 pLOg-을 가지고 Test.cpp에에서C++에서 로그 파일을 만드는 방법
log.cpp
#include "log.h"
#include <ctime>
#include <iostream>
using namespace std;
Log::Log(char* filename) {
//ofstream m_stream(filename);
m_stream.open(filename);
}
> 쓰기 (기음). 파일을 다시 쓰는 이유와 왜 파일을 쓰는 지 이해할 수 없습니다.
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;
};
관련 : HTTP : //log4cpp.sourceforge. net/ –
'std :: ios :: out | std :: ios :: end', 그래서 당신은 파일의 끝에서 시작합니다. – Xeo
어디에 추가해야합니까? .open (file, std :: ios :: out | std :: ios :: end) – user1165435