내가하는 작업은 문자열 벡터를 만들고 문자열을 추가 한 다음 문자열을 삭제하는 것입니다. 스위치 케이스는 경우에 큐를 추가하는 옵션 1.C++의 스위치 케이스 메뉴에서 문자열을 벡터에 추가하는 방법
//gaming Queue
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int choice;
string input;
bool menu = true;
vector<string> favGames;
while (menu){
cout <<"Welcome to the favorite game queue please add your favorite games:\n";
cout <<"1-Add a favorite game.\n";
cout <<"2-List of your favorite games.\n";
cout <<"3-Remove a game.\n";
cin >> choice;
switch (choice)
{
case 1:
cout << "Please add a favorite game to the queue: \n";
string input;
cin >> input;
favGames.push_back(input);// Here is my problem it just jumps to case 2 and shows an error
break;
case 2:
cout << "Here is a list of your favorite games.\n";
break;
default:
cout << "You made an illegal choice.\n";
}
}
return 0;
}
'문자열 입력'을 두 번째로 선언합니다. – Seltymar
이 코드가 사례 2로 점프 할 수있는 유일한 방법은 사용자가 실제로 2를 입력으로 입력하는 경우입니다. 그리고 오류가 있다고하지만 오류가 실제로 무엇인지는 말하지 않습니다. –
@Seltymar는 단 한 번만 필요하다면 케이스 또는 외부에 선언해야합니까? – Migdotcom