使用std :: string ptr打印std :: string时出错

时间:2017-11-29 12:30:10

标签: c++ string stdstring

我正在尝试使用std :: string ptr打印std :: string,如下所示,但收到错误:

Error   1   error C2679: binary '<<' : no operator found which takes
 a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>'
 (or there is no acceptable conversion) 

代码:

#include <stdio.h>
#include <iostream>

int main()
{
    std::string * strPtr = new std::string("Hello World!\n");
    std::cout << (std::string)*strPtr;

    delete strPtr;

    return 0;
}

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

知道了......我没有包含#include<string>。我的错。添加头文件后,它工作。

相关问题