#include <fstream>
using namespace std;
void CDuiMainFrame::TextFileWrite(string strData)
{
char pPath[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, pPath, MAX_PATH);
char *pTemp = strrchr(pPath, '\\');
*pTemp = 0x00;
strcat(pPath, "\\data.txt");
ofstream out;
out.open(pPath, ios::trunc);//iso::trunc表示在打开文件前将文件清空,由于是写入,文件不存在则创建
out << strData.c_str() <<"\n";
out.close();
}
//去除空格
void trim(string &s)
{
int index = 0;
if (!s.empty())
{
while ((index = s.find(' ', index)) != string::npos)
{
s.erase(index, 1);
}
}
}
void CDuiMainFrame::TextFileRead(string &strData)
{
char pPath[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, pPath, MAX_PATH);
char *pTemp = strrchr(pPath, '\\');
*pTemp = 0x00;
strcat(pPath, "\\data.txt");
///LOG(INFO) << "读取本地文件数据" << endl;
char buffer[10240];
ifstream in;
in.open(pPath, ios::in);
if (!in)
{
///LOG(ERROR) << "打开文件失败!" << endl;
}
in.getline(buffer, '\n');
strData = buffer;
in.close();
}