写了一个记录操作数据的类,用来抓at指令来着。没有效率和其他的考虑,在这记录下。
CDebugTools.h
#ifndef CDEBUGTOOLS_H_H
#define CDEBUGTOOLS_H_H
#include <string>
#include <fstream>
#include <iosfwd>
class CDebugTools{
public:
static CDebugTools& GetInstance();
void AddToLog(std::string str);
private:
CDebugTools(){m_log.open(m_strLogName.c_str());};
CDebugTools(const CDebugTools&){};
CDebugTools& operator=(const CDebugTools&){return *this;};
private:
std::ofstream m_log;
// 日志名称
static const std::wstring m_strLogName;
};
#endif
CDebugTools.cpp
#include "stdafx.h"
#include "CDebugTools.h"
using namespace std;
const wstring CDebugTools::m_strLogName = L"./deto.log";
CDebugTools& CDebugTools::GetInstance()
{
static CDebugTools s_DebugTools;
return s_DebugTools;
}
void CDebugTools::AddToLog( std::string str )
{
m_log.write(str.c_str(),str.length());
m_log.flush();
}