以下是我正在编写的相当简单的程序中的代码片段。虽然我有Java的背景,但我对C++还比较新手,因此可能会对打印值的方式有先入为主的看法。 我的问题是当我执行下面这行代码时:
cout << "Please enter the weight for edge " << verticies[i] << endl;
我收到一个错误信息,说操作数与 << 指定的运算符不匹配。基本上是说我不能做 cout << verticies[i]。
为什么会发生这种情况?
以下是代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string verticies[6] = { "AB", "AC", "AD", "BC", "BD", "CD" };
int edges[6];
for (int i = 0; i < 6; i++)
{
cout << "Please enter the weight for edge " << verticies[i] << endl;
}
system("PAUSE");
return 0;
}
<string>
吗? - Cameronstdafx.h
,对于小程序来说,预编译头文件并不值得麻烦。 - Thomas Matthews