cin >> entero

Hi guys, I got stuck and I dont know what's wrong with this code. The isEven is a function created by me, but the thing is that the debbuger says the != opperator doesnt match.

cout << "Enter some integer to see if is even." << endl
<< "Enter the EOF character to end input." << endl;
int entero;
while((cin >> entero) != EOF)
cout << "\nThe number " << entero << " is " << isEven (entero);
Where is EOF decleard?
And if you want to compare a number to a string EOF you need to put it inside "EOF" like that and type cast from a int to a char\ string.
You could try
while((cin >> entero) && !cin.eof())
or simply
while (cin >> entero)
though these will end when a non-numeric character is entered.
Chrevil, the second option works for what I want, however, I was looking at a code of Dietel C++ and he has the next code in the definition of a memeber function of a userdefined class.

void GradeBook::inputGrades()
int grade;

cout << "Enter the letter grades." << endl
<< "\nEnter the EOF character to end input";

while ( ( grade = cin.get() ) != EOF )

Why that is supposed to work and not mine??
Last edited on
> but the thing is that the debbuger compiler says the != opperator doesnt match.
So you don't understand the message, fine. ┬┐why are you rephrasing it?

cin >> entero is different than
grade = cin.get()
The return type is different in each case.

cin.get() has the return type of the member function get() In the example shown the returned value is of type int

cin >> entero returns the stream object itself. When used in a conditional test, it gives a boolean (true/false) result according to the state of the stream.
thank u sir
Topic archived. No new replies allowed.