Quote (Minkomonster @ Feb 20 2014 02:19am)
You aren't wrong. std::cin does have a tendency to provoke input validation concerns. But there are ways around this without introducing strings. Especially for a beginner, let's not bog him down with things he hasn't learned yet.
The following will loop until the user enters an integer:
Code
int d;
while(!(std::cin>>d))
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
Thank you was going to post this. You can also parse cin.good() and cin.eof() to tell if cin read correctly.
Quote (m0hawk @ Feb 20 2014 03:14am)
I think the idea is that parsing from the string is more practical than handling cin directly. But thx for the detailed answer
How is it more practical? Not only do you have to use getline() to grab your string, you also have to validate user string input before trying to parse it for your required integers. If you think strings are the answer for everything then you have a long way to go.