我希望创建一个应用程序,使用C++的boost库在目录及其子目录中搜索文件。我不想遇到像阿拉伯文件名这样的UNICODE文件的麻烦。那么我该怎么办呢?
更新:
#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()'|