Please someone help me out with this question.
I want to input only integer number, except character and even <whitespace>
if I enter character or Whitespace >> then output " Please enter an integer:"
(I want to use the form as below by using While loop)
thank u
1 2 3 4 5 6 7 8
cout << "How many student would you like to add: ";
while (!(cin >> istudent))
{
cout << "Please enter an integer:\n";
cin.clear();
cin.ignore(256, '\n');
}
Thank you Handy Andy and SakurasouBusters. But I could not run your code perfectly, I did not know why bros. could you guys check for me once again please. Thank you
And we need user can input: <whitespace> enter
then run the output after that . that's is something that i could not fix it. thank u 2 you.
Check your string to verify it only contains digits. (#include <cctype> and use std::isdigit().)
(If you wish to act on user just pressing Enter or anything else, now is the time to do it.)
Convert to int using one of the functions in <string>.
How many student would you like to add : @$%^$% < enter >
---> output : please enter an integer number : hdnfvjfn < enter >
---> output : please enter an integer number : <whitespace> <enter>
---> output : please enter an integer number:
that is what I want to do, especially WHITESPACE is which I could not make it
when i type an space and then enter, the output is :
_
_
_
_
so it mean the computer can not read the whitespace. hopefully you understand my case , ~.~ thank you so much for helping me SakurasouBusters.
It can read whitespace, but the formatted input does skip whitespace by default.
Therefore, when you have typed <whitespace> <enter>, which are both white, it is still reading input until you give non-white.
E.g. ---> output : please enter an integer number : <whitespace> <enter>7<whitespace>
will read the 7.