首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

问个do while 的 有关问题

2012-09-29 
问个do while 的 问题求大神来解释下我标注的do while的问题啊int main (){mapstring,vectorstring ch

问个do while 的 问题
求大神来解释下我标注的do while的问题啊
int main ()
{
  map<string,vector<string> >children;
string surname, childname;
do{ 
cout<<"enter surnames (ctrl+z to stop):"<<endl;
cin>>surname;
if(!cin)//什么样的输入流是无效的呢??[color=#FF99CC][/color]
break;//end of input part one
vector<string> chd;
pair<map<string,vector<string> >::iterator,bool> ret=children.insert(make_pair(surname,chd));
  if(!ret.second){
cout<<"repeated surname: "<<surname<<endl;
continue;
}

cout<<"enter children's name :"<<endl;
while(cin>>childname)
ret.first->second.push_back(childname);
cin.clear();
}while(cin);//为什么不可以while(cin>>surname)???[u][/u][b][/b]

[解决办法]
cin>>surname;当输入的内容不能被收取时,if(!cin) cin返回false
[解决办法]
这个东西和新手乐园应该有差距

热点排行