I am trying to take in a phrase from the user and reverse the order of the words and print this back out. For example "hello world" becomes "world hello".
I have found other questions similar to mine on here and most of the "up-voted" answers suggest doing it this way:
std::list<std::string> input;
std::list<std::string>::iterator iter;
std::string phrase;
std::string word;
std::cout << " Enter the phrase you wish to reverse " << std::endl;
std::cout << " >> ";
std::getline(std::cin, phrase);
std::istringstream iss(phrase);
while (iss >> word) {
input.push_front(word);
}
for (iter = input.begin(); iter != input.end(); ++iter) {
std::cout << *iter << " ";
}
However, this does not work for me. When I run the code, it never stops to allow for input. I can not figure out why it does not stop to allow me to type input.
How can I do this so that I can type in a phrase and have the program read it in word by word?
Edit: I am using MS Visual Studio 2015 and compiling using the debug (f5) option.