可能重复:
在 getline() 方面需要帮助
在下面的代码中,我的 getline 被完全跳过并且不提示输入。
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <istream>
using namespace std;
int main ()
{
int UserTicket[8];
int WinningNums[8];
char options;
string userName;
cout << "LITTLETON CITY LOTTO MODEL: " << endl;
cout << "---------------------------" << endl;
cout << "1) Play Lotto " << endl;
cout << "q) Quit Program " << endl;
cout << "Please make a selection: " << endl;
cin >> options;
switch (options)
{
case 'q':
return 0;
break;
case '1':
{
cout << "Please enter your name please: " << endl;
getline(cin, userName);
cout << userName;
}
cin.get();
return 0;
}
}