why is this not working i get a problem with the "=="?

int var1, var2;

if ((cin>>var1)==false)
{
cout << "Fehler" << endl;

}

if((cin>>var2)==false)
{
cout << "Fehler" << endl;
}
else
{
cout << var1 << "/" << var2 <<" "<< var1 / var2 << endl;
}
Last edited on
Instead of saying "why is this not working" perhaps you should say "I expect this to happen, but this is happening instead when I enter this input." Or is it compiling? Do you get an error? How are we to know with your incomplete code snippet and vague question?

Please provide as much relevant information as possible when you ask questions (including, if possible, a complete compilable code snippet that reproduces the issue.)

Error (active) no operator "==" matches these operands . I have a problem with he condition in the brackets and dont know why. When I put cin>>var1 outdise the brackets everything is fine but i m lookin now a YT video and this same command work.
sorryy for the vague hahah :D :D
An istream can be converted to a bool where a value of type bool is expected. An argument to operator== is not such a place.

The more usual expression would be:
1
2
3
if (!(cin >> var1)) 
{
    // ... 


Although, you could explicitly cast the result to bool and compare it to false.
1
2
3
if (static_cast<bool>(cin >> var1) == false)
{
    // ... 
Last edited on
thank you very much
Topic archived. No new replies allowed.