gpt4 book ai didi

c++11 - 如何解决在此范围内未声明的 “' shared_ptr错误?

转载 作者:行者123 更新时间:2023-12-02 05:36:43 25 4
gpt4 key购买 nike

我正在尝试在Raspberry Pi上编译带有shared_ptrs的代码:

#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;
}

我收到以下错误:
test.cpp: In function 'int main(int, char**)': test.cpp:4:4: error: 'shared_ptr' was not declared in this scope
shared_ptr<string> message1(new string("Hello Raspberry Pi C++11"));
^ test.cpp:4:21: error: expected primary-expression before '>' token
shared_ptr<string> message1(new string("Hello Raspberry Pi C++11"));
^ test.cpp:4:70: error: 'message1' was not declared in this scope
shared_ptr<string> message1(new string("Hello Raspberry Pi C++11"));

我正在使用以下命令进行编译: g++ -std=c++11 -o test test.cppG++版本是g++(Raspbian 4.8.2-21〜rpi3rpi1)4.8.2

请帮忙。

最佳答案

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

#include <memory>

关于c++11 - 如何解决在此范围内未声明的 “' shared_ptr错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29276312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com