C++ 编译C++;带boost库的代码

C++ 编译C++;带boost库的代码,c++,boost,makefile,C++,Boost,Makefile,我正在尝试编译()。这段代码要求以前安装libboost和libpng库,我成功地完成了安装 但当我执行“make”命令时,终端上会出现以下错误 spam.cpp:169:26: error: ‘class boost::filesystem3::directory_entry’ has no member named ‘leaf’ spam.cpp:179:20: error: ‘class boost::filesystem3::path’ has no member named ‘nati

我正在尝试编译()。这段代码要求以前安装libboost和libpng库,我成功地完成了安装

但当我执行“make”命令时,终端上会出现以下错误

spam.cpp:169:26: error: ‘class boost::filesystem3::directory_entry’ has no member named ‘leaf’
spam.cpp:179:20: error: ‘class boost::filesystem3::path’ has no member named ‘native_file_string
有办法解决这个问题吗?我应该安装另一个libboost版本吗

感谢您的关注。

leaf()
已弃用

请参阅此已弃用函数及其新名称列表:

编辑以供注释:

应该是这样的:

  boost::filesystem::path p("foo.txt");
  std::cout << p.filename() << std::endl; 
boost::filesystem::path p(“foo.txt”);
std::cout
leaf()
已被弃用。见:
您可以尝试在不使用
BOOST_FILESYSTEM_NO_DEPRECATED

的情况下播放。通过@Salgar和@Jean-Baptiste Yunè的建议,以及在makefile中的-lboost_FILESYSTEM之后添加-lboost_system,问题得以解决。谢谢大家。

我更正了第二个错误,将本机文件字符串替换为文件字符串(),但当我将leaf()替换为path().filename()时,出现了另一个错误。这段代码是:stringfilename=file->path().fileName()//以前是file->leaf()。错误是这样的:spam.cpp:168:42:错误:需要将'boost::filesystem3::path'转换为非标量类型'std::string{aka std::basic_string}'再次感谢salgar。但是我希望代码独立于文件名运行(我不想直接在代码上通知文件名)。有没有一个好的方法来更改这段代码?再次感谢。这段代码是字符串fileName=file->path().fileName()。我应该把file->path().filename()转换成字符串吗?谢谢你的回复。我更正了第二个错误,将本机文件字符串替换为文件字符串(),但当我将叶()替换为路径().filename()时,出现了另一个错误。这段代码是:stringfilename=file->path().fileName()//以前是file->leaf()。变量文件是一个目录迭代器。错误是错误是这样的:spam.cpp:168:42:错误:将'boost::filesystem3::path'转换为非标量类型'std::string{aka std::basic_string}'必需
path.filename()
不是类型
string
它是类型
path
。如果您想从中获取
字符串
,可以尝试
native()
path.filename().native()
)。再次感谢您的回复。现在我有以下错误:spam.cpp:168:30:error:“((boost::iterator_facade*)(&file))->boost::iterator_facade::operator->()->->boost::filesystem3::directory_entry::path”没有类类型。我会继续努力,再次谢谢你。