我在計算機實驗室,沒有一位導師可以找出爲什麼我的getline
無法正常工作。它沒有正確存儲信息(只存儲1或2個字母)。有誰知道這是爲什麼?爲什麼getline如此不一致?
void addMovie(Inventory movie[], int &count)
{
string s;
int i;
cout << "Please enter the SKU " << endl;
cin >> i;
movie[count].sku = i;
cout << "Please enter the name of the movie you wish to add " << endl;
cin.ignore('\n');
getline(cin, s, '\n');
movie[count].title = s;
count++;
}
作爲一個說明,你或許應該使用某種比C數組標準集裝箱。你似乎沒有在這裏做任何界限檢查。 – tadman
您不必在'getline'中輸入''\ n''。這是默認的分隔符。 – chris