出于某种原因,我一直收到这样的错误:没有匹配'运算符>>'(操作数类型为'std::is



我一直收到这个错误:

C:UsersOwnerDownloadss tlmadlibsgamemain.cpp|69|error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'})| 

每当我运行这个程序时,我都会使用代码块第69行似乎有问题,但我不知道为什么。

#include <cmath>
#include <iostream>
using namespace std;
// cout<<" enter second operator: "//
// cin>> oprator;
// if (oprator == '+'){cout<<"enter third number: ";
// cin>>num3;}
// if (oprator == '*'){cout<<"enter third number: ";
// cin>>num3;}
// if (oprator == '/'){cout<<"enter third number: ";
// cin>>num3;}
// if (oprator == '^'){cout<<"enter third number: ";
// cin>>num3;}
// if (oprator == '-'){cout<<"enter third number: ";
// cin>>num3;}//
double num1;
int E = 10000;
double num2;
double letterinto(double)
{
double turninto = num2 = num1;
return turninto;
}
double num3;
double times(double)
{
double result = num1 * num2;
return result;
}
double square(double)
{
double result = num1 * num1;
return result;
}
double addition(double)
{
double answer = num1 + num2 + num3;
return answer;
}
double decl;
double timesorplus(double)
{
double decision = decl * 0;
return decision;
}
string name;
char oprator;
void sayHi(string name)
{
cout << "Hello " << name;
}
double factorial(double n)
{
if (n <= 1)
return 1;
else
return n * factorial(n - 1);
}
int a;
string getmode(int mchoice)
{
string fchoice;
switch (mchoice)
{
case 0:
fchoice = "normal";
double _finite = pow(2, 1023);
char again = 'y';
while (again == 'y')
{
if (num1 > _finite)
{
cout << "error: number is bigger than the limit " << (again = 'n');
}
else
{
// if (num1 = 'a';){cout<<"-->";cin>>num2;oprator = '>';}
cout << "hello enter first number : ";
cin >> num1;
cout << "enter operator: ";
cin >> oprator;
if (oprator == '+' || '*' || '/' || '^' || '-')
{
cout << "enter second number: ";
cin >> num2;
}
if (oprator == '+' && '+')
{
cout << " the answer is!: n"
<< addition(num1 + num2 + num3 || num1 + num2) << endl;
}
else if (oprator == '>')
{
cout << "A = " << letterinto(num1) << endl;
}
else if (oprator == '*')
{
cout << "the answer is!: n" << times(num1 * num2) << endl;
}
else if (oprator == '/')
{
cout << "the answer is!: " << num1 / num2 << endl;
}
else if (oprator == '^')
{
cout << "the answer is!: " << pow(num1, num2) << endl;
}
else if (oprator == 'f')
{
cout << "the answer is!: " << sqrt(num1) << endl;
}
else if (oprator == '-')
{
cout << "the answer is!: " << num1 - num2 << endl;
}
else if (oprator == '!')
{
cout << "the answer is!: " << factorial(num1) << endl;
}
else
{
cout << "invalid operator n";
}
cout << "would you like to go again (y/n) ";
cin >> again;
}
}
}
}
int main()
{
cin >> getmode;
}

该代码本应为程序启用模式,但由于某种原因,它一直给我错误,代码块的版本是20.03

尚未读取逻辑,但问题出现在cin >> getmode行。代替getmode的应该是左值引用,但您传递了函数名。此int main()将修复编译错误。

int main()
{
int x;
cin >> x;
getmode(x);
}

p.S.更改代码,使其至少可读