开发者社区> 问答> 正文

vs2010中使用boost库遍历目录下的文件?报错

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;
}


展开
收起
爱吃鱼的程序员 2020-06-20 19:41:14 511 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    C++已经够糟糕了

    还加上Java那套玩意


    2020-06-20 19:41:30
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载