所以我有以下代码:
char command;
cin >> command;
if ( command == 'P' ) {
do_something();
}
if ( command == 'Q' ) {
cout << "Exit\n";
exit(0);
}
else {
cout << "command= " command << endl; //use for debugging
cout << "Non-valid input\n";
exit(1);
}
cout << "exit at completion\n";
exit(0);
}
当我使用输入时P
,我do_something()
完成后的输出是:
"output from do_something() function"
command= P
Non-valid input
我的问题是为什么我仍然会在第一个 if 语句中调用Non-valid input
after ?do_something()
AKA 为什么 elsedo_something()
完成后仍然运行?