#include <string>
#include <vector>
#include <map>
int _tmain(int argc, _TCHAR* argv[])
{
std::fstream File;
File.open("E:\\茂名石化错误码.txt");
std::vector<std::string> vecErrorCode;
std::map<std::string, int> mapErrStatistics;
while (!File.eof())
{
std::string strErrCode = "";
char szErrCode[256];
// 以下两种写法都可
//inFile.getline(szErrCode, 256, '\n');
std::getline(File, strErrCode);
vecErrorCode.push_back(strErrCode);
}
File.close();
// 保存统计信息
File.open("E:\\错误统计表.csv", std::ios::binary | std::ios::out);
for (auto itrMap:mapErrStatistics)
{
File << itrMap.first << ',' << itrMap.second << std::endl;
}
File.close();
return 0;
}
ios::in input 以输入方式打开文件。
ios::out output 以输出方式打开文件。
ios::app append 以追加方式打开文件。
ios::ate at end 打开文件时,定位到文件尾。
ios::binary binary 以二进制方式打开文件,默认是文本方式。
ios::trunc truncate 打开文件时,把文件长度截断为0。