std::string strDir = std::string(szSetPath) + std::string("\\out.txt");
ifstream ifs;
ofstream ofs(strDir.c_str());
vector<string> csv_vec = statdir.BeginBrowseFilenames("*.*");
static int csv = 0;
for(vector<string>::const_iterator it = csv_vec.begin(); it < csv_vec.end(); ++it)
{
string strTemp = *it;
if (strTemp.find("fix.csv") != string::npos)
{
ifs.open(strTemp);
if (!ifs.rdbuf()->is_open())
{
// 打開文件錯誤
}
// 取文件大小
ifs.seekg(0,std::ios::end);
int nLen = ifs.tellg();
char* pBuffer = new char[nLen];
if (pBuffer == NULL)
{
//
}
memset(pBuffer ,0,nLen);
// 恢復遊標
ifs.seekg(0);
ifs.read(pBuffer,nLen);
if(ifs.gcount() != nLen)
{
//
}
CString strFind(pBuffer);
strFind.Replace(sztmp, "");
strFind.Trim();
strFind += "\n";
ofs.write(strFind, strFind.GetLength());
delete []pBuffer;
csv++;
ifs.close();
}
}
ofs.close();
C++文件讀寫
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.