C++错误:与"运算符<<"不匹配(操作数类型为"std::istream {aka std::basic_istream}"和"int")



所以我正在用 C++.
编写这个简单的计算器错误消息说:

main.cpp:38:6:错误:"运算符<<"不匹配(操作数类型为"std::istream {aka std::basic_istream}"和"int")
cin<<anotherQ;

代码是:

using namespace std;
int main()
{
int running = 0;
while(running != 1) {
float num1;
float num2;
char op;
int anotherQ;
cout<<"Enter 1 for '+', 2 for '-', 3 for '*', 4 for '/': ";
cin>>op;
cout<<"n";
cout<<"Enter a number: ";
cin>>num1;
cout<<"n";
cout<<"Enter another number: ";
cin>>num2;
cout<<"n";
if (op=='1') {
cout<<"The answer is "<<num1 + num2<<endl;
}
else if(op == '2') {
cout<<"The answer is "<<num1 - num2<<endl;
}
else if(op=='3') {
cout<<"The answer is "<<num1 * num2<<endl;
}
else if(op=='4') {
cout<<"The answer is "<<num1 / num2<<endl;
}
else {
cout<<"Wrong operator"<<endl;
running = 1;
}
cout<<"Do you want to do another sum 0 for Yes and 1 for No "<<endl;
cin<<anotherQ;
if (anotherQ == 0) {
cout<<"Hmm.., Think u like maths well let's do another sum"<<endl;
}
else if (anotherQ == 1) {
cout<<"Ok well byee!"<<endl;
running = 1;
}
else {
cout<<"crrrcrr u have given a wrong command byeeeeeeeeeeeeeeeee! I was not desinged for handling such complex commands  as I was made by a 9 year old boy u will pay for it"<<endl;
running = 1;            
}
}
return 0;
}

你有

cin<<anotherQ;

在您的代码中,这是不正确的。

cin >> anotherQ;

是正确的语法。

最新更新