我正在写一个C++程序,显示一个男人的2个输出,使它看起来像他在跳跃,如果你按下输入。如果输入'q',程序应该停止。这是我所得到的。按Enter键继续或q退出C++
//此程序将显示跳跃的人。
包括 包括使用命名空间std;
int main() {
string user_input;
do
{
cout << endl << endl << endl << endl << endl << endl << endl
<< endl << endl << endl << endl << endl << endl << endl
<< endl << endl << endl << endl << endl << endl << endl
<< endl << endl << endl << endl << endl << endl;
cout << " O" << endl;
cout << " /|\\" << endl;
cout << " ()" << endl;
cout << "------------------------------------------------------------" << endl;
cout << "Press ENTER to continue or enter q to quit:";
getline(cin, user_input);
cout << endl << endl << endl << endl << endl << endl << endl
<< endl << endl << endl << endl << endl << endl << endl
<< endl << endl << endl << endl << endl << endl << endl
<< endl << endl << endl << endl << endl << endl;
cout << " \\O/" << endl;
cout << " | " << endl;
cout << "/\\" << endl << endl;
cout << "------------------------------------------------------------" <<endl;
cout << "Press ENTER to continue or enter q to quit:";
} while(getline(cin, user_input));
return 0;
}
我一直在尝试了几个小时,我仍然无法弄清楚如何,如果你输入q停止程序。
我已经试过while语句的变体,如
而(函数getline(CIN,USER_INPUT)& & USER_INPUT =! 'Q')
,但它不工作。任何帮助都将不胜感激。
这不是家庭作业,我只是想学习C++编码,而且在我正在学习的书的早期活动中。尽管谢谢你的帮助。 –
好吧,你可能想要做的是重构你的循环,以便检查是不是像这样(从cin和检查读取)更像是:{循环代码..... getline(cin,user_input); bool input = user_input!=“q \ n”;} while(input)“\ n”是新行的转义字符,打印结果与endl相同,但包含在字符串“ – JoyStickFanatic
”我不确定你的意思。或者更详细地描述一下? –