【发布时间】:2018-05-13 04:06:16
【问题描述】:
我正在尝试使用 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;
}
我在这里做错了什么?
【问题讨论】:
-
您使用的是哪个编译器?因为在 GCC 7.2 中有效。此外,不需要强制转换
(std::string)*strPtr。 -
I can't replicate your error。问题中的代码不是导致错误的代码。
-
我使用的是 Visual Studio 2008
-
这是 stackoverflow.com/questions/22724064/… 的完整副本,但遗憾的是,如果有人想接手,我已经在其他东西上使用了我的标志。