C++ 编译程序时出错
我正在编译一个开源项目,但我遇到了一个以前从未见过的错误:C++ 编译程序时出错,c++,C++,我正在编译一个开源项目,但我遇到了一个以前从未见过的错误: luascript.cpp: In member function ‘bool LuaInterface::loadDirectory(const string&, Npc*, bool)’: luascript.cpp:742:41: error: ‘boost::filesystem2::basic_path<std::basic_string<char>, boost::filesystem2::path
luascript.cpp: In member function ‘bool LuaInterface::loadDirectory(const string&, Npc*, bool)’:
luascript.cpp:742:41: error: ‘boost::filesystem2::basic_path<std::basic_string<char>, boost::filesystem2::path_traits>::string_type’ has no member named ‘string’
在旧版本的boost文件系统中,方法filename()的返回类型是string_类型,而不是path类型。字符串类型没有与路径类型相反的成员文件名()
对于您正在使用的较旧版本的boost,您只需删除代码中的.string()部分。此处的快速浏览,但在创建之前似乎需要使用“string”。基本上,这是一个简单的问题error@Coffee关于如何解决此问题,您有什么建议吗?请访问helpdesk.stackexchange.net
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(); //This is line 742
if(boost::filesystem::is_directory(it->status()))
{
if(recursively && !loadDirectory(it->path().filename() + "/" + 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;
}