c++ - 错误: 'operator>>' 不匹配(操作数类型为 'std::basic_istream<char> cin>> salary >> endl;^

标签 c++

我有以下代码:

#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;
}

我试图理解创建错误:

no match for 'operator>>' (operand types are 'std::basic_istream::__istream_type {aka std::basic_istream}' and '') cin>> salary >> endl; ^

最佳答案

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

所以更正你的下一行

cin>> salary >> endl;

cin>> salary;

关于c++ - 错误: 'operator>>' 不匹配(操作数类型为 'std::basic_istream<char> cin>> salary >> endl;^,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30554798/

相关文章:

c++ - Boost::asio -- UnregisterWaitEx' 尚未声明

c++ - 将 1d 矩阵模式设置为等于 2d 矩阵

c++ - 提升图形库 : setting edge weight values

C++ 类定义中函数的多重定义

c++ - Xlib。调整大小后重绘(重新填充)闪烁的形状窗口

c++ - 非静态成员函数的无效使用 在类模板的成员函数的实例化中?

c++ - 用类处理二维数组的一个小问题

c++ - 如何强制使用 QT 进行蓝牙配对?

c++ - 根据源文件所在的目录更改 cmake CMAKE_CXX_FLAGS

C++ 非静态函数作为变量