【问题标题】:error: no match for 'operator>>' (operand types are 'std::basic_istream<char> cin>> salary >> endl; ^错误:'operator>>' 不匹配(操作数类型是 'std::basic_istream<char> cin>> Salary >> endl; ^
【发布时间】:2015-08-13 19:24:38
【问题描述】:

我有以下代码:

#include <QCoreApplication>
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int salary;
    int childeren;
    cout << "please type base salary=";
    cin>> salary >> endl;
    cout<< "plz type count your childeren=";
    cin >> childeren >> endl ;
    int Totalsalary=salary + childeren*10;
    cout<< Totalsalary<< endl;
    return 0;
}

我试图理解创建错误:

'operator>>' 不匹配(操作数类型是 'std::basic_istream::__istream_type {aka std::basic_istream}' 和 '') cin>> 工资 >> endl; ^

【问题讨论】:

  • cin&gt;&gt; salary &gt;&gt; endl; 省略endl。

标签: c++


【解决方案1】:

std::endl 用于创建行尾和刷新流缓冲区。它应该与std::cout 一起使用,而不是与std::cin 一起使用。

所以更正你的下面一行

cin>> salary >> endl;

到

cin>> salary;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-18
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多