我遇到問題,我的for-loop跳過了getline函數。如果我用std :: cin代替它,那麼它就可以工作,所以我認爲它與我在getline中輸入的內容有關。For-Loop跳過getline C++
這是我的代碼。
void setLocations(int amount) {
locations = new std::string[amount];
locations[0] = startingLocation;
// starts at 1 because we want to skip first index. The amount is set at 2 by default, so the loop should iterate at least once.
for (int x = 1; x < amount; x++)
std::getline(std::cin, locations[x]);
}
http://stackoverflow.com/questions/6819082/stdgetline-on-stdcin – HelloWorld
http://stackoverflow.com/questions/257091/how- do-i-flush-the-cin-buffer –