问个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
[解决办法]
这个东西和新手乐园应该有差距