智能感知:没有运算符"<<"与这些操作数匹配
IntelliSense: no operator "<<" matches these operands
我收到错误:
IntelliSense: no operator "<<" matches these operands
operand types are: std::ostream << std::string c:UsersmohammadDocumentsVisual Studio 2013Projectssumming a list of numbersumming a list of numbersumming a list of number.cpp 10
这是代码:
// summing a list of number.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
int sum(int a[], int from, int size, const string& context, int depth)
{
string indent(depth, '|');
cout << indent << context << "(a, " << from << ", " << size << ")" << endl;
int result = 0;
if (size == 1)
{
result = a[from];
}
else if (size > 1)
{
int midpoint = size / 2;
int left = sum(a, from, midpoint, "left", depth + 1);
int right = sum(a, from + midpoint, size - midpoint, "right", depth + 1);
result = left + right;
cout << indent << "=" << left << "+" << right << endl;
}
cout << indent << "=" << result << endl;
return result;
}
int main(){
int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
cout << "sum = " << sum(a, 0, 10, "sum", 0) << endl;
getchar();
}
为什么它说由于 std 和 ostream 而出现错误,而我已经包含了 iostream 和 std?
我正在使用VS-2013。
通过更改此行:
#include "iostream"
到
#include <iostream>
并将环添加为:
#include <string>
成功了。
向包含区域添加新行,其中包含以下内容: #include "string"
.智能感知甚至您的生成系统都不知道此字符串类型对象是什么。您应该为 std 中的类型字符串包含上面提到的标头(这是声明),以便让双方都知道它是什么以及您的意思。
您还应该包含这样的字符串库,即#include <string>
并从 #include"iostream"更改为#include <iostream>
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 控制允许动态运行c++的并发操作数
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- <<操作员在下面的行中工作
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- C++ 带有向量的 IF 计算操作数
- 是否所有C++运算符都接受操作数?
- 一元*运算符的操作数是否期望一个 prvalue
- 与'operator='不匹配(操作数类型'String'且"void")
- 不正确的操作数类型 MSVC
- C2678 二进制 '==':未找到采用 'Card' 类型左操作数的运算符(或者没有可接受的转换)
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 我的运算符重载是否有效<<(流插入)左操作数不是 ostream
- 没有运算符"="与这些操作数匹配,JUCE 窗口演示应用程序
- 如果我在指针中使用 ++ 操作数,我的值就会出错
- 二进制表达式的操作数无效 - 使用 for 和迭代器
- C2679 二进制"<<":未找到采用右操作数类型的运算符
- CPP 运算符重载操作数位置 [] 与 ==