辅助记忆“map”使用细节的经典例题

  “ 使用下标访问 map 对象”有不少细节值得记忆,为此,《C++ Primer》中还单列一个标题“下标行为的编程意义 ”,其中的举例就是下面这段代码,自己先理解代码,然后再去看相关解析,会发现,其实他包含的内容比想到的多,未来编程过程中可能频繁遇到类似使用,在此做个印象提醒:

1      // count number of times each word occurs in the input 
2      map<string, int> word_count; // empty map from string to int 
3      string word; 
4      while (cin >> word) 
5        ++word_count[word]; 

 

转载于:https://www.cnblogs.com/tingshuixuan2012/archive/2013/04/15/3022651.html

你可能感兴趣的:(辅助记忆“map”使用细节的经典例题)