/*==================================================================*\
*
* C++ map 运用---统计单词出现的次数
*
\*==================================================================*/
#include <iostream>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
int main()
{
map<char, int> word_count;// empty
char word[]="abcdefg";
for (int i = 0; i <strlen(word); i++)
{
++word_count[word[i]]; // 用下标访问
}
map<char, int>::iterator iter; // iter 为pair 类型(value_type)
for (iter = word_count.begin(); iter != word_count.end(); iter++)
{
cout << "[" << iter->first << "] = " << iter->second << endl;//iter->first:key,iter->second:value
}
return 0;
}