读取文件, 统计字符,忽略大小写

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;
}
posted @ 2014-07-18 21:07  wu_overflow  阅读(211)  评论(0编辑  收藏  举报