我几乎完成了这个菜单并按照我想要的方式工作。但是,当我在不输入任何内容的情况下按 Enter 时出现断言错误。这是代码
#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
bool menu ()
{
string input = "";
bool exitVar;
do
{
system("cls");
cout << " _ _ _ _ _ _ _ _ " << endl
<< " |_|_ _|_| |_| |_|_ |_| |_|_|_| " << endl
<< " |_|_|_|_|_| |_| |_|_|_ |_| |_|_ " << endl
<< " |_| |_| |_| |_| |_| |_|_|_| |_|_| " << endl
<< " |_| |_| |_| |_| |_|_| |_|_ _ " << endl
<< " |_| |_| |_| |_| |_| |_|_|_| " << endl
<< " _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " << endl
<< " _|_|_| |_| |_| |_|_|_| |_|_|_| |_|_|_ |_|_|_| |_|_|_ " << endl
<< " |_|_ |_| _ |_| |_|_ |_|_ |_|_|_| |_|_ |_|_|_| " << endl
<< " |_|_ |_|_|_|_|_| |_|_| |_|_| |_|_| |_|_| |_|_|_ " << endl
<< " _ _|_| |_|_| |_|_| |_|_ _ |_|_ _ |_| |_|_ _ |_| |_|_ " << endl
<< " |_|_| |_| |_| |_|_|_| |_|_|_| |_| |_|_|_| |_| |_| " << endl;
cout << "\n Welcome to Psuedo Mine Sweeper!!\n\n\n\n";
cout << " <S>TART"
<< "\n\n <E>XIT\n\n";
cout << "\t\t\tPlease enter a valid menu option: ";
getline(cin,input);
input[0] = toupper(input[0]);
}while(input[0] != 'S' && input[0] != 'E' || input.length() != 1 || cin.peek() != '\n');
if (input[0] == 'S')
exitVar = true;
else
exitVar = false;
return exitVar;
}
我对调试断言值不是太有经验。我尝试独立运行菜单