带有一些文本的字符串变量的链值,并在C++中将其打印到标准输出

Ras*_*sto 0 c++ string stdout bit-shift

我想做一些非常简单的事情:我的函数有字符串参数,我想将它链接到一些常量字符串,然后将结果输出到控制台,如下所示:

void test(string s){
    cout << "Parameter of this function was: " << s;
}
Run Code Online (Sandbox Code Playgroud)

在其他语言中,这样的链接有效,但在C++中,编译器不满意: error C2679: binary '<<': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

Mar*_*utz 6

你可能忘了#include <string>#include <iostream>.