c++中cin按什么键结束输入?(Ctrl+z没用 CTRL+c直接结束)程序如下
#include<map>#include<string>#include<iostream>#include<iterator>usingstd::string;usi...
#include<map>
#include<string>
#include<iostream>
#include<iterator>
using std::string;
using std::map;
using std::iterator;
using std::cin;using std::cout;using std::endl;
int main()
{
string s;
map<string,int>counters;//store each word and an associated counter
//read the input,keeping track of each word ang how often we use it
while(cin>>s)
++counters[s];
//write the words and associated counts
for(map<string,int>::const_iterator it=counters.begin();it!=counters.end();++it){
cout<<it->first<<"\t"<<it->second<<endl;
}
return 0;
} 展开
#include<string>
#include<iostream>
#include<iterator>
using std::string;
using std::map;
using std::iterator;
using std::cin;using std::cout;using std::endl;
int main()
{
string s;
map<string,int>counters;//store each word and an associated counter
//read the input,keeping track of each word ang how often we use it
while(cin>>s)
++counters[s];
//write the words and associated counts
for(map<string,int>::const_iterator it=counters.begin();it!=counters.end();++it){
cout<<it->first<<"\t"<<it->second<<endl;
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询