IntelliSense:没有运算符“<<”匹配这些操作数
IntelliSense: no operator "<<" matches these operands
我遇到错误:
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。
将包含以下内容的新行添加到您的包含区域:
#include "string"
。
IntelliSense 甚至您的构建系统都不知道这个字符串类型 objects 是什么。您应该为来自 std 的类型字符串包含上面提到的 header (这是声明),让双方都知道它是什么以及您的意思。
通过更改此行:
#include "iostream"
进入
#include <iostream>
并将字符串添加为:
#include <string>
成功了。
您还应该像这样包含字符串库,即 #include <string>
并将 #include "iostream" 更改为 #include <iostream>
我遇到错误:
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。
将包含以下内容的新行添加到您的包含区域:
#include "string"
。
IntelliSense 甚至您的构建系统都不知道这个字符串类型 objects 是什么。您应该为来自 std 的类型字符串包含上面提到的 header (这是声明),让双方都知道它是什么以及您的意思。
通过更改此行:
#include "iostream"
进入
#include <iostream>
并将字符串添加为:
#include <string>
成功了。
您还应该像这样包含字符串库,即 #include <string>
并将 #include "iostream" 更改为 #include <iostream>