它得到第一個字符串和第一個雙倍後程序不會得到其他字符串。C++如何使用getline將完整的字符串存儲到字符串數組中?
for (int i = 0; i< NUM_MOVIES; i++)
{
cout << "Enter the name of the movie: ";
getline(cin, names[i]);
cout << "How much did " << names[i] << " earn <in millions>: ";
cin >> earnings[i];
cout << endl;
}
謝謝你的工作。 ws做什麼? – user3462406
@ user3462406,http://en.cppreference.com/w/cpp/io/manip/ws – chris
@ user3462406:'std :: cin >> std :: ws'會吃掉所有的空白字符(換行符,製表符,空格),有效地將該流引導至下一個非空白字符以供閱讀。 – AndyG