![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
input control
if i write the code like...
int number;
cout << "Enter a number: "; cin >> number;
while(!cin)
{
cin.clear();
cin.ignore(100,'\n');
cout << "Enter a NUMBER: " << endl;
cin >> number;
}; |
|
|
|
|
|
#2 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>but if i have a variable of "char" type, it wont wont print the warning if i enter digits instead of characters.
That's because all user input is character based. Even if you type a digit, it's still the character representation of that digit. >how do i solve this? You have to manually validate each character using one of the functions in <cctype> or read everything as a string and parse using one of several common methods.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#3 |
|
Programmer
|
rgr that, the last solution will do
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading character input into an array (raw mode) | shoeyfighter | C | 3 | Nov 2nd, 2006 4:49 PM |
| questions on windows sendMessage and RichEdit control | nomer | C++ | 1 | Mar 3rd, 2006 3:51 AM |
| User input | jayme | C++ | 38 | Nov 25th, 2005 8:27 PM |
| C programing control of the Serial Port. | Light | C++ | 5 | Feb 24th, 2005 3:14 PM |
| Show web user control hidden | see07 | C# | 1 | Feb 2nd, 2005 11:35 AM |