detection of integer values

closed account (96AX92yv)
hello, i am having trouble finding a way to detect integers from an external text file. i currently have this code:

1
2
3
4
5
6
7
8
while(inputfile.get(wc))
{
			char character = inputfile.get(wc);
			if (character + 1 != NULL)
			{
				cout << character << endl;
			}			
		}


this does not work as if (character + 1 != NULL) comes up with errors.
is there a way to detect ints? can someone help?
Integers can be tested by the condition (character >= '0' && character <= '9').
Your while loop does not seem to be correct either. Why are you reading a character again inside the loop after reading it while checking for the while condition?
http://www.cplusplus.com/reference/cctype/isdigit/

Or simply try to read an integer
1
2
3
4
5
int n;
if( std::cin>>n )
   //read successful
else
   //it was not a number 
closed account (96AX92yv)
thanks that helps alot
Topic archived. No new replies allowed.