C++文件读写

std::string strDir = std::string(szSetPath) + std::string("\\out.txt");
ifstream ifs;
ofstream ofs(strDir.c_str());
vector csv_vec = statdir.BeginBrowseFilenames("*.*");


static int csv = 0;

for(vector::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/c++)