#include <vector> #include <string> #include <algorithm> #include <iostream> #include <iterator> #include <map> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { vector<string> vec; vec.push_back("This"); vec.push_back("is"); vec.push_back("a"); vec.push_back("key"); vec.push_back("this"); vec.push_back("key"); vec.push_back("A"); vec.push_back("Thas"); vec.push_back("kEy"); map<string,int> words; vector<string>::iterator it = vec.begin(); for(it; it != vec.end(); ++it) { if(words.find(*it) != words.end() ) { int i = words[*it]; ++i; words[*it] = i; } else { words.insert(map<string,int>::value_type(*it,1)); } } map<string,int>::iterator mapit = words.begin(); for(mapit;mapit != words.end();++mapit) { cout<< mapit->first<<" "<<mapit->second<<endl; } return 0; }