编写程序统计并输出所读入的单词出现的次数
#include <iostream>
#include <string>
#include <utility>
#include <map>
#include <stdlib.h>
using namespace std;
int main()
{
map <string,int> word_count;
map <string,int> ::iterator map_it=word_count.begin();
string word;
while(cin> > word)
++word_count[word];
cout < <map_it-> first;
cout < <map_it-> second;
system( "pause ");
return 0;
}
我这个不对啊 该怎么编阿
[解决办法]
#include <iostream>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
map <string,int> word_count;
map <string,int> ::iterator map_it; //word_count.begin() is invalid because word_count is empty now
string word;
while(cin> > word)
++word_count[word];
for (map_it=word_count.begin(); map_it!=word_count.end(); ++map_it)
cout < <map_it-> first < < "\t " < <map_it-> second < <endl;
system( "pause ");
return 0;
}