Hello all, please help solve this..i cannot make an input and output inside the switch cases statement.when i put the input output string type out of the switch case statement, it worked.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
char choice;
cout << "Demo Switch Case + input string\n\n";
cout << "Please enter 1 to continue\n";
cin >> choice;
switch (choice)
{
case '1':
{
cout << "Please enter a string: \n\n";
getline(cin, str);
cout << str;
break;
}
default:
{
cout << "Invalid input\n\n";
break;
}
}
return 0;
}