For-Loop Skipping getline C++ -


this question has answer here:

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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -