Hi guys, I'm trying to learn C++, and I'm just wondering what the deal is with this:
Code:
#include <iostream>
#include <string>
int main()
{
std::string s;
std::cout << "Please enter a string: ";
std::cin >> s;
std::cin.ignore();
std::cout << "\nYou entered: " << s << "\n";
std::cin.get();
}
The problem is when a user enters a string of more than 1 word, it'll only print the first. I.E say I enter "Hello there" it will say "You entered: Hello" instead of "You entered: Hello there". I'm guessing cin doesn't read whitespace or something, so I'm just wondering what is the way around this... Ok thanks!