首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >boost-filesystem中的分段故障?

boost-filesystem中的分段故障?
EN

Stack Overflow用户
提问于 2014-06-13 21:09:09
回答 1查看 1.3K关注 0票数 2

我有一个函数可以迭代指定目录中的所有文件和目录。

为此,我使用了boost文件系统。

这是它的代码:

代码语言:javascript
复制
void Utility::index(string IPath)
{
  path p(IPath) ; 
  string extension ; 
  directory_iterator end ; 
  for(directory_iterator it(p); it<end; ++it)
    {
      lastPath = it->path().string() ;
      cout<<lastPath<<endl ; 
      if(is_symlink(it->path()))
      {
        //cout<<"Found a symlink : "<<it->path()<<endl  ; 
      }
      else if (is_regular_file(it->path()))
      {
         extension = lastPath.substr(lastPath.find_last_of(".")+1) ;
         master<<lastPath<<endl ; 
       }
      else if(is_directory(it->path()))
      { 
        try
        {
          index((it->path()).string()) ;
        }
        catch(boost::filesystem3::filesystem_error e) 
        {
          cout<<e.what()<<endl ; 
        }
      }
    }
}

当我在目录"/“上运行这个函数时,它给出了分段(错误)。

看着gdb中的回溯,我无法理解问题出在哪里。

回溯是:-

EN

回答 1

Stack Overflow用户

发布于 2014-06-13 22:21:56

取消引用或递增有效的directory_iterator can throw

所有使用it->++it的代码都需要在try块中以处理错误条件。考虑扩展现有的try块以包含该代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24206142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档