#include<iostream>
#include<map>
using namespace std;
int main()
{
string str = "\0";
cout << "please input a string" << endl;
cin >> str;
map<char,int> map1;//定义map对象
//迭代器遍历输入的字符串
for(string::iterator it = str.begin();it != str.end();it++){
//插入字符,如果插入失败则返回false
pair<map<char,int>::iterator,bool> ret = map1.insert(pair<char,int>(*it,1));
//每插入失败一次,对map中第二个元素计数,并把字符存入map中
if(ret.second == false){
map<char,int>::iterator mit = ret.first;
mit->second++;
}
}
//C++11的定义格式,遍历输出map的内容
for(auto i:map1){
cout << i.first << "---->" << i.second << endl;
}
return 0;
}