1
回答
vs2010中使用boost库遍历目录下的文件
百度AI开发者大赛带你边学边开发,赢100万奖金,加群:418589053   

vs2010下用c++的boost库写的一个遍历目录下文件夹的程序,运行时报错,如图:

代码如下:

#include <iostream>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include <fstream>
using namespace std;
void GetAllFileOfPath(const boost::filesystem::path &base_dir, const std::string &extension,vector<string>& container)
{

boost::filesystem::path full_path( boost::filesystem::initial_path() );
full_path = boost::filesystem::system_complete( base_dir );
if (!boost::filesystem::exists (full_path) && !boost::filesystem::is_directory (full_path))
return;
for (boost::filesystem::directory_iterator it (full_path); it != boost::filesystem::directory_iterator (); ++it)
{
if (boost::filesystem::is_directory (it->status ()))
{
GetAllFileOfPath (it->path (), extension, container);
}
if (boost::filesystem::is_regular_file (it->status ()) && boost::filesystem::extension (it->path ()) == extension)
{
container.push_back(it->path().string());
}
}




}




int main()
{
vector<string> container;
std::string extension (".pcd");
transform (extension.begin (), extension.end (), extension.begin (), (int(*)(int))tolower);
string s="data/";
boost::filesystem::path base_dir=s;
GetAllFileOfPath(base_dir,extension,container);
for (auto it=container.begin();it!=container.end();it++)
{
cout<<*it<<endl;
}

return 0;
}


举报
阿超一代
发帖于4年前 1回/1K+阅
顶部