读取文件, 统计字符,忽略大小写
int main (int argc, char* argv[])
{
std::ios::sync_with_stdio (false);
ifstreamfile;
file.open(argv[1]);
mapword_count;
string word,line;
while(getline (file, line)) {
istringstream record (line);
while(record >> word) {
for (auto&ch : word)
ch = tolower(ch);
word.erase(remove_if (word.begin (), word.end (), [] (const char&ch){return ispunct (ch); }));
++word_count[word];
}
}
for (constauto &w : word_count) {
cout<< w.first << " ocurrs " << w.second;
cout<< ((w.second > 1) ? " times" : " time") <<endl;
}
return0;
}
{
}