寫了一個記錄操作數據的類,用來抓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();
}