set容器

来源:互联网 发布:mac itunes 照片 删除 编辑:程序博客网 时间:2024/06/05 11:29
使用set和map容器,可以很容易地实现一个单词统计程序,这个程序只统计那些不在排除集中的单词
void restricted_wc(ifstream &remove_file, map<string, int> &word_count){     set<string> excluded;    //  set to hold word we'll ignore     string remove_word;     while(remove_file >> remove_word)          excluded.insert(remove_word);     string word;     while(cin >> word)         // increment counter only if the word is not in excluded         if(! excluded.count(word))               ++word_count[word];
来自C++ Primer
原创粉丝点击