当我选择actres或电影标题时,我正在尝试编写一个存在while循环的while循环。但由于某种原因,它没有告诉我while (selecton)
行有错误。有人有想法吗?
string selection;
while ( selection )
{
cin >> selection;
if ( selection == "actress" )
{
cout << "hey" << endl;
break;
}
else if ( selection == "movie title" )
{
cout << "bye";
break;
}
else
{
cout << "Please choose a selection";
}
}
答案 0 :(得分:6)
应该是while(cin>>selection)
但是最好写while(getline(cin,selection))
,这样就不会跳过白线。