繁体   English   中英

出于某种原因,我不断收到此错误:“运算符&gt;&gt;”不匹配(操作数类型为“std::istream”{又名“std::basic_istream”<char> &#39;}

[英]for some reason I keep getting this error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'}

我不断收到此错误:

C:\Users\Owner\Downloadss tl\madlibsgame\main.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);
}

PS更改您的代码以使其至少可读

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM