C++文件读写

来源:互联网 发布:大数据,银行风险 编辑:程序博客网 时间:2024/06/07 07:11
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();

0 0
原创粉丝点击