类型"int"和"<未解析的重载函数类型>"到二进制"运算符<<"的操作数无效
Invalid operands of types ‘int’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
我试图将两个数组求和为第三个数组!!
int main()
{
int RoadHeights[2000] , TopoHeights[2000] , Differences[4000] , i , n ;
cout << "Enter the number of stations! " << endl;
cin >> n;
cout << "Enter the heights of stations on Road! " << endl;
for ( i=0 ; i<n ; i++ )
cin >> RoadHeights[i];
cout << "Enter the heights of stations on Ground! " << endl;
for ( i=0 ; i<n ; i++ )
cin >> TopoHeights[i];
cout << "Height differences are: " << endl;
for ( i=0 ; i<n ; i++ )
cout << Differences [4000] = RoadHeights[i] - TopoHeights[i] << endl;
return 0;
}
2: Differences[4000]越界,且=运算符的优先级低于<<操作符,所以用括号把表达式括起来:
cout << (Differences [i] = RoadHeights[i] - TopoHeights[i]) << endl;
否则,首先计算cout << Differences[i]
,返回ostream&
,有效地变成
cout << Differences[i];
cout = (RoadHeights[i] - TopoHeights[i]) << endl;
显然第二行是错误
这将解决你的编译器问题,但我猜你有更多的逻辑问题在那里。例如,硬编码数组大小,但用户输入的大小之后?如果n
是5000
呢?试着用std::vector
代替。
std::vector<int> RoadHeights, TopoHeights, Differences;
int i , n ;
cout << "Enter the number of stations! " << endl;
cin >> n;
RoadHeights.resize(n);
TopoHeights.resize(n);
Differences.resize(n);
// proceed as normal
相关文章:
- 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等)设置为零