在下面的代碼,我的函數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;
}
}
它是如何不工作?在什麼條件下?運行時錯誤?編譯器錯誤?你想做什麼?你能把它結晶到一個更小的例子嗎? – 2011-05-10 16:55:58
不錯的方式讓人們開始思考... – 2011-05-10 16:56:27
也,這功課?如果是這樣,它應該被貼上標籤。 – 2011-05-10 16:56:40