错误:std :: cin的“ operator >>”不匹配

NewCoderVini

我正在为练习编写代码:

编写一个完整的程序,从用户读取一个整数,使用doubleNumber()函数将其加倍,然后将加倍的值输出到控制台。

#include <iostream>

int doubleNumber(int x)
{
    return 2*x;
}

int main()
{

    int a;
    std::cout << "Enter an integer :" ;
    std::cin >> a >> std::endl;
    std::cout << doubleNumber(a) << endl;
    return 0;
}

我在编译时遇到的错误是:

error: no match for 'operator >>'

有任何想法吗?

现实主义者

你有两个问题。您缺少endl的标准输入法。由于endl来自std,因此确定范围是必需的。

另一个问题是使用cin时,无需添加std :: endl。std :: endl仅代表行尾(创建新行)。cin命令仅接受输入,并且std :: endl不是您可以输入的变量。

如果您修复了这些问题,则程序将正常运行。

固定代码:

#include <iostream>

int doubleNumber(int x)
{
    return 2*x;
}

int main()
{

    int a;
    std::cout << "Enter an integer :" ;
    std::cin >> a;
    std::cout << doubleNumber(a) << std::endl;
    return 0;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误:与“ operator +”不匹配(操作数类型为“ std :: __ cxx11 :: list <int>”和“ int”)|

C ++编译错误-不匹配'operator ='

重载给我错误:“ operator <”不匹配

如何理解C ++错误,“不匹配'operator =='(操作数类型为'std :: pair'和'const int')”?

为什么在使用`std :: find`时错误显示'operator =='不匹配?

编译错误:与“ operator--”不匹配

与“ operator <<”不匹配

与“ operator =”不匹配

不断得到错误''operator >>不匹配';

Cout无法正常工作-(错误:“ operator <<”不匹配)

分叉进程时std :: cin不阻塞

错误:不匹配'operator >>'(操作数类型为'std :: istream'{aka'std :: basic_istream <char>'}和'const int')|

'std :: cin >>'中'operator >>'的模棱两可的重载

std :: cin中的运算符>>不匹配

'std :: operator ...中的'operator <'不匹配。这是什么意思?

'std :: operator中的'operator <<'不匹配

错误:“ operator ==”不匹配,该怎么办?

错误:boost :: tuple的'operator =='不匹配

错误:“operator[]”不匹配?

'operator[]' 不匹配(操作数类型是 'std::unique_ptr<std::vector<int> >' 和 'int')

解决错误:与 operator[] 不匹配

C++ 设置迭代器错误:“operator+=' 不匹配

与 std 中的“operator<<”不匹配

错误:“operator==”不匹配,但确实在基类上定义

错误:'operator[]' 不匹配(操作数类型是 'std::map<std::__cxx11::basic_string<char>, int>' 和 'char')

错误:“operator<<”不匹配(操作数类型为“std::basic_ostream<char>”和“<unresolved重载函数类型>”)

编译器错误:“operator[]”C++ 不匹配

出于某种原因,我不断收到此错误:“operator>>”不匹配(操作数类型为“std::istream”{aka 'std::basic_istream<char>'}

错误:'operator>>' 不匹配(操作数类型为 'std::istream' {aka 'std::basic_istream<char>'} 和 'Oper')