我对C++有点新鲜,我试图编写一个代码来制作一个基本的C++计算器,但是当我尝试构建它时弹出如下错误:C++错误:'操作符>>'不匹配'
“错误:'operator >>'不匹配(操作数类型是'std :: basic_ostream :: __ ostream_type {aka std :: basic_ostream}'和'char')|”
的代码是:
#include <iostream>
#include <string.h>
using namespace std;
void add(int x, int y)
{ cout<<"First number:";
cin>>x;
cout<<endl<<"Second number:";
cin>>y;
cout<<endl<<x<<"+"<<y<<"="<<x+y;
}
void subtract(int x, int y)
{
cout<<"First number:";
cin>>x;
cout<<endl<<"Second number:";
cin>>y;
cout<<endl<<x<<"-"<<y<<"="<<x-y;
}
void multiply(int x, int y)
{
cout<<"First number:";
cin>>x;
cout<<endl<<"Second number:";
cin>>y;
cout<<endl<<x<<"*"<<y<<"="<<x*y;
}
void divide(int x, int y)
{
cout<<"First number:";
cin>>x;
cout<<endl<<"Second number:";
cin>>y;
cout<<endl<<x<<"/"<<y<<"="<<x/y;
}
int main()
{
int x,y;
char z;
cout << "\t\t\t Welcome to the C++ Calculator." << endl;
cout << "What operation would you like to perform? ";
cout << "Add(+), Subtract(-), Multiply(*), Divide(/):"<<
cin >> z;
cout <<endl;
if (z=='+')
add(x,y);
else if (z=='-')
subtract(x,y);
else if (z=='*')
multiply(x,y);
else if (z=='/')
divide(x,y);
else if ((z!='+')&&(z!='-')&&(z!='*')&&(z!='/'))
cout<<"Unknown symbol.";
return 0;
}
哪行做了错误发生在? – user2079303
@ user2079303因为我一直在读,所以可能是在main()中:'char z;/* ... */cin >> z;'** edit **:或_very near there_ - 当您看到它时... –
请以理智的方式格式化您的代码。另外,仔细看看你的编译器错误的行。该行不完全正确。 – Barry