我想创建一个应用程序,使用C++的boost库在目录和子目录中搜索文件也我不想遇到像名为阿拉伯文件的文件的UNICODE文件的问题。 那我该怎么做呢?使用boost库在目录和子目录中搜索文件C++
UPDATE:
#include <iostream>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#define BOOST_FILESYSTEM_NO_DEPRECATED
using namespace boost::filesystem;
using namespace std;
bool find_file(const path & dir_path, // in this directory,
const std::string & file_name, // search for this name,
path & path_found) // placing path here if found
{
if (!exists(dir_path)) return false;
directory_iterator end_itr; // default construction yields past-the-end
for (directory_iterator itr(dir_path);
itr != end_itr;
++itr)
{
if (is_directory(itr->status()))
{
if (find_file(itr->path(), file_name, path_found)) return true;
}
else if (itr->path().filename() == file_name) // see below
{
path_found = itr->path();
return true;
}
}
return false;
}
int main()
{
path myPath = "C:";
string myFile = ".doc";
path myfound = "c:";
find_file(myPath, myFile, myfound);
}
我也试过这个代码,但它不会编译它表明这个错误并不少
undefined reference to `boost::filesystem3::path::filename() const
也:
X:\mingw\boost\boost_1_47_0\boost\system\error_code.hpp|214|undefined reference to `boost::system::generic_category()'|
尝试boost :: filesystem – mikithskegg 2012-02-20 18:07:36
我试过上面的代码,但徒劳无功我使用codeblocks和提升1_47_0 – pourjour 2012-02-20 18:35:06
这不是一个编译器错误,这是一个链接器错误。 – ildjarn 2012-02-20 18:36:30