Here is the code
int main()
{
int x;
while((cin >> x) >= 2){
cout<<"Greater than 2";
}
}
and I am using these preprocessor directives
#include <iostream>
#include <ios>
#include <string>
#include <iomanip>
using std::cout; using std::cin;
I am getting error in the while loop, it says this:
no operator ">=" matches these operands -- operand types are: std::basic_istream<char, std::char_traits<char>> >= int
I am new to c++
In the while condition, you are comparing cin>>x and 2.
I believe you wanted to check for conditions where x>= 2. But, in your code, the compiler is comparing the output of cin>>x with 2. As the output of the cin operator is not INT, hence you are getting the error.
For more information on this, you can refer to: https://devdocs.io/cpp/io/cin
As far as correcting the code is concerned, try while( cin>>x && x>=2) because here the compiler will first execute the cin and then it will execute the comparision.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments