C++11 我如何解决一个问题';共享ptr&x27;未在此范围内声明;错误?

C++11 我如何解决一个问题';共享ptr&x27;未在此范围内声明;错误?,c++11,compiler-errors,shared-ptr,C++11,Compiler Errors,Shared Ptr,我正在尝试在Raspberry Pi上编译带有共享\u ptr的代码: #include <iostream> using namespace std; int main(int argc, char* argv[]){ shared_ptr<string> message1(new string("Hello Raspberry Pi C++11")); cout << *message1 <<endl; return 0; }

我正在尝试在Raspberry Pi上编译带有共享\u ptr的代码:

#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
   shared_ptr<string> message1(new string("Hello Raspberry Pi C++11"));
   cout << *message1 <<endl;
   return 0;
}
#包括
使用名称空间std;
int main(int argc,char*argv[]){
共享消息1(新字符串(“Hello Raspberry Pi C++11”);

cout您需要在文件开头添加内存头

#include <memory>
#包括

如果上述解决方案在包含标头之后仍然不起作用,请确保您正在向编译器传递参数--std=c++11


如果是用gcc编译的,则应包含标题tr1标题,即#include代替和std::tr1::shared_ptr。

gcc多年来不需要tr1标题,也不需要很多版本(包括几个稳定版本)。
#include <memory>