The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-22-2008
Darklight Darklight is offline
Registered User
 

Join Date: Apr 2008
Posts: 12
C++ how to isdigit() a negative number?

hi people,

I have a function which I am passing a stream which is basically postfix notation

Code:
    	if(isdigit(in.peek()))
		{
			in >> number;
			nums.push(number);
		}
		else if (strchr("+-*/", in.peek( )) != NULL)
		{
			in >> symbol;
			do_operation(symbol, nums, okay);
		}
    		else
		{	
			in.ignore();
		}
the stream I am passing would look like this:

Code:
2 -3 +
which is effectivley 2 + -3

the problem is that isdigit(in.peek()) is reading the '-' as a char and not part of the negative number..... what can I do?

Cheers in advance
Reply With Quote
Forum Sponsor