중 문자열 첨자는 거의이 메뉴는 다 내가 원하는 방식으로 작업했다. 그러나 아무 것도 입력하지 않고 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;
}
입니다. 독립 실행 형 메뉴를 실행 해 보았습니다
은의 getline 후 입력을 인쇄 해 봅니다 당신은 아마 문제를 볼 것이다! – Mario