gpt4 book ai didi

c++ - 使用 native() boost 路径访问器

转载 作者:行者123 更新时间:2023-11-30 02:49:45 24 4
gpt4 key购买 nike

我收到这个错误:

luascript.cpp: In member function ‘bool LuaInterface::loadDirectory(const string&, Npc*, bool)’:
luascript.cpp:744:69: error: no matching function for call to ‘LuaInterface::loadDirectory(boost::filesystem3::path, Npc*&, bool&)’
luascript.cpp:744:69: note: candidate is:
luascript.cpp:736:6: note: bool LuaInterface::loadDirectory(const string&, Npc*, bool)
luascript.cpp:736:6: note: no known conversion for argument 1 from ‘boost::filesystem3::path’ to ‘const string& {aka const std::basic_string<char>&}’

还有这段代码:

    bool LuaInterface::loadDirectory(const std::string& dir, Npc* npc/* = NULL*/, bool recursively/* = false*/)
{
StringVec files;
for(boost::filesystem::directory_iterator it(dir), end; it != end; ++it)
{
std::string s = it->path().filename().string();
if(boost::filesystem::is_directory(it->status()))
{
if(recursively && !loadDirectory(it->path() / s, npc, recursively))
return false;
}
else if((s.size() > 4 ? s.substr(s.size() - 4) : "") == ".lua")
files.push_back(s);
}

std::sort(files.begin(), files.end());
for(StringVec::iterator it = files.begin(); it != files.end(); ++it)
{
if(!loadFile(dir + (*it), npc))
return false;
}

return true;
}

我按照这里有人的建议更改了第一个 if 以使其更清晰,但他们还告诉我使用 native() 路径访问器。

最佳答案

那……你为什么不呢? :)

if(recursively && !loadDirectory((it->path() / s).native(), npc, recursively))

到目前为止,

可能是有意义的
  • it->path()/s引入一个变量
  • 阅读documentation for Boost Filesystem
    该代码表明您正在尝试递归遍历文件系统树。你看过 boost::recursive_directory_iterator 了吗?

关于c++ - 使用 native() boost 路径访问器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20937758/

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