c++ - 打印出 std::string

标签 c++ iostream fstream cout

在下面的示例代码中

    std::string result = exec( "dir" ) ;
    cout<<result;

出现以下错误

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string

我怀疑有一种特殊的方法可以打印出 std::string

请帮我调试一下。

此外,我还包含了 iostream.hfstream.hstream 头文件。

最佳答案

我怀疑您需要使用 std:: 来限定 cout

    std::cout << result;

或将 using namespace::std 添加到您的 cpp 文件的顶部。

关于c++ - 打印出 std::string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10668128/

相关文章:

C++ ifstream/fstream 破坏数据

c++ - 直接使用成员函数与 unordered_set

c++ - sh_none 不是 'std::basic_filebuf<_Elem,_Traits>' 的成员

c++ - 读写同一个文件c++

c++ - 如何在 C++ 中打印 Unicode 字符?

c++ operator<<的多重定义

c++ - 使用 rdbuf 复制文件并从文件中读取不一致?

c++ - 用一个给定半径的圆覆盖最大点数的算法

c++ - 当 for 循环的停止条件是一个单独的指针变量时,这意味着什么?

c++ - Rosenbrock 检验函数计算的准确性