智能感知:没有运算符"<<"与这些操作数匹配

IntelliSense: no operator "<<" matches these operands

本文关键字:lt 操作数 感知 运算符 智能      更新时间:2023-10-16

我收到错误:

 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>