私は多少C++を使い始めましたが、基本的なC++電卓を作るためのコードを書こうとしましたが、ビルドしようとすると次のエラーが表示されます:C++エラー: 'operator >>'と一致しません
"エラー: '演算子>>'に一致しません(オペランドの型は 'std :: basic_ostream :: __ ostream_type {別名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; '**編集**:またはそれの近くの_ _ - あなたがそれを見るとき... –
コードを正式な形式で書式化してください。また、コンパイラが間違っている行を注意深く見てください。その行はあまり正しくありません。 – Barry