![]() |
#2
mxs8102010-10-09 15:38
|

我想遍写一个查找单词的程序,create_denary可以创建但是到cin<<be的上一步就结束了,请问是哪的原因阿
#include<iostream>
#include<map>
#include<string>
#include<utility>
using namespace std;
string change_word(string word);
void create_denary(map<string,string> &L)
{
string firstw,secondw;
while(cin>>firstw>>secondw)
{
pair<map<string,string>::iterator,bool> rep=L.insert(make_pair(firstw,secondw));
if(!rep.second) cout<<"键值重复"<<endl;
}
map<string,string>::iterator it=L.begin();
while(it!=L.end())
{ cout<<it->second<<" ";
it++;}
cout<<"完成"<<endl;
}
void change_word(map<string,string> &L,string word)
{
map<string,string>::iterator map_it=L.find(word);
if(map_it!=L.end())
cout<<map_it->second<<endl;
}
int main(void)
{
string be;
map<string,string> L;
create_denary(L);
cin>>be;
change_word(L,be);
return 0;
}
#include<iostream>
#include<map>
#include<string>
#include<utility>
using namespace std;
string change_word(string word);
void create_denary(map<string,string> &L)
{
string firstw,secondw;
while(cin>>firstw>>secondw)
{
pair<map<string,string>::iterator,bool> rep=L.insert(make_pair(firstw,secondw));
if(!rep.second) cout<<"键值重复"<<endl;
}
map<string,string>::iterator it=L.begin();
while(it!=L.end())
{ cout<<it->second<<" ";
it++;}
cout<<"完成"<<endl;
}
void change_word(map<string,string> &L,string word)
{
map<string,string>::iterator map_it=L.find(word);
if(map_it!=L.end())
cout<<map_it->second<<endl;
}
int main(void)
{
string be;
map<string,string> L;
create_denary(L);
cin>>be;
change_word(L,be);
return 0;
}