c++ - C++ 错误:'operator<<' 不匹配(操作数类型是 'std::istream {aka std::basic_istream}' 和 'int')
问题描述
所以我正在用 C++ 编写这个简单的计算器。
错误消息说:
main.cpp:38:6:错误:'operator<<' 不匹配(操作数类型为'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;
是正确的语法。
推荐阅读
- javascript - 第二个标题粘在滚动上
- mysql - 仅选择给定输入的最大 id
- c# - 发布我的网站时出错
- javascript - 如何逐行制作textarea行自动方向?
- animation - Angular 5 Animations - 浏览器历史上的路由器转换
- c# - Xamarin 表单 Listview - 更新 ObservableRangeCollection 时 UI 不更新
- vim - VIM缩进设置不起作用
- javascript - es6 中的最佳 Ptarices / Notation 与 some ( OR ) 的条件
- python - keras:expected dense_1_input 有 2 维
- html - Animate cc html 画布引用 MovieClip