好问题
Good  Question
  • 首 页
  • 问题
    • PHP
    • JAVA
    • CPlusPlus
    • C#
    • SQL
  • 关 于
  • 联 系
在标准C++中如何递归地迭代每个文件及目录 关闭 返回上一级  

在标准C++中如何递归地迭代每个文件及目录
+ 查看更多

发布日期:2018-02-26 13:58
分类:CPlusPlus
浏览次数:51
在标准C++中如何递归地迭代每个文件及目录

回答

在标准C++中,从技术角度来说没有这种方法,因为标准C++没有目录的概念。
如果你想扩展自己库的功能,你可以用 Boost.FileSystem。
它已经被TR2(C++ Technical Report 2)接受,所以这样就能尽可能地使你的接口保持接近标准。
举个例子,这个例子是直接从网站上拿过来的:
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->leaf() == file_name ) // see below
    {
      path_found = itr->path();
      return true;
    }
  }
  return false;
}
上一篇在C++中如何得知一个文件的大小
在C++中如何使用 clock()函数下一篇
下一篇在C++中如何使用 clock()函数

最新文章

  • 函数`__construct`用来干嘛的
    发布日期:2018-03-26
  • 通过访客的IP得到他们的地区
    发布日期:2018-03-26
  • 合并两个PHP对象的最好的方法是什么?
    发布日期:2018-03-26
  • 该如何把一该如何把一个对象转化成数组?
    发布日期:2018-03-26
  • 什么是输出缓冲区?
    发布日期:2018-03-26
  • 在PHP中怎么把用逗号分隔的字符串分隔在一个数组里?
    发布日期:2018-03-26
  • 在PHP中使用foreach循环时查找数组的最后一个元素
    发布日期:2018-03-26
关于好问
收集整理一些有用的问题和回答,造福中国的程序旺和IT喵们!
友情链接
起飞页 
相关信息
版权声明
Copyright © 2016 - 2017  苏州卡达网络科技有限公司 好问 GOODQ.TOP 备案号:苏ICP备09008221号-5