我收到错误:
IntelliSense: no operator "<<" matches these operands
operand types are: std::ostream << std::string c:\Users\mohammad\Documents\Visual Studio 2013\Projects\summing a list of number\summing a list of number\summing 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();
}
当我已经包含iostream和std时,为什么会说std和ostream出现错误?
我正在使用VS-2013。
答案 0 :(得分:9)
通过更改此行:
#include "iostream"
进入
#include <iostream>
并添加字符串:
#include <string>
它有效。
答案 1 :(得分:4)
在您的包含区域添加以下新行:
#include "string"
。
IntelliSense甚至构建系统都不知道这个字符串类型的对象是什么。你应该为std中的类型字符串包含上面提到的标题(这是声明),让它们都知道它是什么以及你的意思。
答案 2 :(得分:0)
您还应该包括这样的字符串库,即SET @Time = CONVERT(TIME(5), STUFF(SUBSTRING(@BadgeTimbrature, 25, 28), 3, 0, ':'))
,并从#include“ iostream”更改为#include <string>