Newbie C++ programmer again...

Robert Ambrose rna@testpt.com
Fri, 18 Aug 2000 07:56:42 -0700 (MST)


What's happening with the 'cout >> tester;' is you are 'extracting' an int
value from the input stream.  Because tester is an int, 'cout >> tester;'
is trying to convert what you typed into an integer and put the result
into tester.  If the conversion fails, i.e. you type non-numeric values as
input, tester is not be changed and will contain whatever was in that
stack location when the program was executed.  

The 'cout >> tester;' returns a true value if the conversion succeeds and
a false value if it fails.  

Here's an example program:

#include <iostream.h>
#include <ctype.h>
 
int main ()
{
	int tester;

	cout << "enter some input:";

	if(cin >> tester)
		cout << "Numeric: " << tester << endl;
	else
		cout << "Not a numeric value" << endl;

	return 0;
}

rna

On Thu, 17 Aug 2000, Eric Samson wrote:

> Hello again all...
> 
> I am trying to figure out the proper way to use the isalpha function, when I 
> enter a digit, it returns 0, and when I enter an alpha character, I get a 
> segmentation fault..  Can anyone tell me what I am doing wrong??
> 
> Thanks in advance,
> 
> Eric
> 
> Program:
> 
> #include <iostream.h>
> #include <ctype.h>
> 
> 
> int main ()
> 
> {
> 
> 	int flag;
> 	int tester;
> 
> 
> 	cout << "\n\nenter some input :";
> 
> 
> 
> 		cin >> tester;
> 
> 
> 		flag = isalpha (tester);
> 
> 
> 
> 		cout << "\n\n" << flag << "\n\n";
> 
> 		return 0;
> 
> 	}
> 
> output:
> ---------------------
> alpha character
> 
> $ ./test
> 
> 
> enter some input :g
> Segmentation fault
> 
> ----------------------
> 
> numeric
> $ ./test
> 
> 
> enter some input :5
> 
> 
> 0
> -----------------------
> 
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
> 
> 
> _______________________________________________
> Plug-devel mailing list  -  Plug-devel@lists.PLUG.phoenix.az.us
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-devel
>