我可以使用cout打印正常变量,但每当我尝试打印一个函数变量(在这种情况下,string input
)时,编译器会发出错误:
C2679:二进制'<<' :找不到哪个操作员需要右手 'std :: string'类型的操作数(或者没有可接受的转换)
我在下面发布了我的代码。有什么我做错了吗?(我使用的是Eclipse的C ++版本)
到目前为止,这是我的代码:
#include <iostream>
using namespace std;
void println(string text) {
cout << text << endl;
}
int main() {
int test = 5;
cout << test;
return 0;
}
答案 0 :(得分:0)
如果您想使用std::string
,则需要添加<string>
!可以声明或甚至定义类型,因为它由IOStream类使用,但实现可以选择不包括整个头。在你的代码中,你似乎得到了std::string
的定义,但没有输出运算符的声明。
答案 1 :(得分:0)
运营商&lt;&lt; for class std :: basic_string在header <string>
中声明。因此,您需要将它包含在您的程序中,编译器将对其进行了解。