1、Log.h
#pragma once
#include<string>
#include<fstream>
using namespace std;
class CLog
{
public:
CLog(void);
~CLog(void);
void AddContent(string strMsg);
};
2、Log.cpp
#include "StdAfx.h"
#include "Log.h"
CLog::CLog(void)
{
}
CLog::~CLog(void)
{
}
void CLog::AddContent(string strMsg)
{
ofstream outfile;
outfile.open("Log.txt",ios_base::app | ios_base::out); //存放数据的文件名
if(outfile.is_open())
{
outfile<<strMsg<<endl; //message是程序中处理的数据
outfile.close();
}
else
{
cout<<"不能打开文件!"<<endl;
}
}