错误:"与'运算符<<'不匹配(操作数类型为 std::istream)
Error : "No match for 'operator <<' (operand types are std::istream)
这是我的第一个StackOverflow,很高兴加入。我目前正在用Stroustrup的"使用C++编程和实践"学习C++,目前我们正在使用他创建的库(#include"std_lib_facilities.h")
我完成了一个练习,犯了这个错误"与'operator<<'不匹配(操作数类型为std::istream)"
我写的程序可能还不完美,但我现在甚至无法编译它。我在其他帖子中读过一些关于"重载运算符"的内容,但我不明白它的含义,也不明白为什么在我的其他文件中,即使加载了相同的库,也不会发生这种情况。
#include "../../std_lib_facilities.h"
int main()
{
double val1 = 0;
double val2 = 0;
cin << val1 << val2 << endl;
if (val1>val2)
cout << val1 << " is larger than " << val2 <<endl;
else
cout << val1 << " is smaller than " << val2 <<endl;
}
您应该在c++中使用>>运算符进行输入。这被称为提取运算符,用于从键盘或其他类似文件中获取值。语法为:
int variableName;
cout << "Enter number";
cin >> variableName;
<lt;operator是插入运算符,用于在屏幕或文件上写入数据。
您应该将operator>>
与std::cin
一起使用,后者是std::istream
,不支持operator<<
。
std::cin >> val1 >> val2;
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 模板元程序查找相似的连续类型名称
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- std::pair的默认构造函数<>将基本类型(int等)设置为零