/************g++ 版本*************/
[root@bogon 11]# g++ --version
g++ (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/************************************/
/*********** *编译提示 ****************/
associate.cc:23:18: error: ISO C++ forbids declaration of ‘w’ with no type [-fpermissive]
for(const auto &w : word_count)
^
associate.cc:23:22: error: range-based ‘for’ loops are not allowed in C++98 mode
for(const auto &w : word_count)
/****************************************/
/**************程序********************/
#include <iostream>
2 #include <map>
3 #include <string>
4 #include <set>
5
6
7 using namespace std;
8
9 int main()
10 {
11 map<string,size_t> word_count;
12 string word;
13 set<string> exclude;
14
15
16 while(cin >> word)
17 {
18 if(word == "quit")
19 break;
20 else if(exclude.find(word) == exclude.end())
21 ++word_count[word];
22 }
23 for(const auto &w : word_count)
29 cout << w.first << ": " << w.second\
30 << ((w.second > 1) ? " times" : " time") << endl;
31 }
/**********************************************************************/