For-Loop Skipping getline C++ -
this question has answer here:
- std::getline on std::cin 2 answers
i'm having problem for-loop skips on getline function. if replace std::cin works, think it's related inputted in getline.
here's code.
void setlocations(int amount) { locations = new std::string[amount]; locations[0] = startinglocation; // starts @ 1 because want skip first index. amount set @ 2 default, loop should iterate @ least once. (int x = 1; x < amount; x++) std::getline(std::cin, locations[x]); }
may use 'std::cin>>somevar' before 'setlocations' function call, doesn't consume newline. resolve, use code segment before 'for' loop
std::cin.ignore(1, '\n');
Comments
Post a Comment