C++primer 11.3.4节练习
练习11.24
将关键字为0的元素的值赋值1;如果没有,创建。
练习11.25
程序会报错。因为v是一个空的容器,代码编译不会出错,运行会提示下标越界;
练习11.26
key_value类型;
mapped_value类型;
1 #include <iostream> 2 #include <string> 3 #include <set> 4 #include <map> 5 #include <algorithm> 6 #include <vector> 7 #include <algorithm> 8 #include <iterator> 9 10 using namespace std; 11 12 int main() 13 { 14 map<string, int> word_count; 15 string word; 16 while (cin >> word) 17 { 18 ++word_count[word]; 19 } 20 system("pause"); 21 return 0; 22 }