![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2007
Posts: 2
Rep Power: 0
![]() |
Find if something is an int
I need to read in a value, declared as
int anIntVariable = 0; via cin cin >> anIntVariable I now need to check if it is indeed an int value. How do I check if this is something other than an integer? |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,254
Rep Power: 5
![]() |
Check the state of the stream. If it can't complete an operation, it will be in an error state. For example;
#include <iostream>
int main()
{
int value;
while (std::cin.eof())
{
std::cin >> value;
if (std::cin.bad()) // if bad data in stream
std::cin.clear(); // clear the error state
}
} |
|
|
|
![]() |
| 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 |
| Wierd compile Error. Need help please. | Keiyentai | Java | 7 | Aug 19th, 2006 2:35 AM |
| Vector problem - find max, min and positions | codylee270 | C++ | 12 | Mar 20th, 2006 1:57 AM |
| Find a matching element in an XML file | Eleo | C# | 2 | Feb 16th, 2006 9:25 PM |
| Median/Mode in arrays? {Need help} | Java|Tera | Java | 27 | Nov 29th, 2005 11:50 AM |
| Program that can find a patern | Anyways | C++ | 2 | Mar 22nd, 2005 3:27 AM |