Quote Originally Posted by monarch_dodra View Post
The std iostreams come with operator<< and operator>>, which basically take the input, and convert it to the corresponding numeric tipe, like this:

Code:
float a;
cin >> a;
This will even work if your input is something like 0.0f, or an hex integer, provided you told your stream you are reading an hex (it can't guess for you)

As for checking for text, if the user types "apple", then the read will "fail" (this is normal), and you will be able to tell your user to try again.

Why would you want to limit the amount of characters? If your user needs 278 characters to input his value, who are you to say it is wrong? And if it is, you should just handle the fault, then tell your user to try again.

Once you are done reading and validating user input, you are 100% guaranteed to have perfectly valid input. It is part of standard methods to never do anything before you have validated the objects you are working with. You can code away without worries

std iostream s are standard, expandable, error tolerant, and safe. atoi is non of those things.
wanting to limit characters for things such as Date of birth and some cant have an incom of £555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555 etc