a word-counting program: /* * word-counting program * in vs2010, not support 1.container initializer and 2.range for */ #include #include #include #include using namespace std; int main(void) { string word; // holds the input word map word_count; // use a set to hold the words we want to ignore set exclude; while (cin >> word) { exclude.insert(word); } cin.clear(); // make cin valid while (cin >> word) { if (exclude.find(word) == exclude.end()) { ++word_count[word]; } } for (map ::iterator iter = word_count.begin(); iter != word_count.end(); ++iter) { cout << iter->first << " occurs " << iter->second << ((iter->second > 1) ? " times" : " time") << endl; } return 0; }