我需要将目录中的所有".xml"文件名保存到向量中.长话短说,我不能使用dirent API.似乎C++没有任何"目录"的概念.
一旦我在向量中有文件名,我就可以迭代并"fopen"这些文件.
有没有一种简单的方法可以在运行时获取这些文件名?
简单的方法是使用Boost.Filesystem库.
namespace fs = boost::filesystem;
// ...
std::string path_to_xml = CUSTOM_DIR_PATH;
std::vector<string> xml_files;
fs::directory_iterator dir_iter( static_cast<fs::path>(path_to_xml) ), dir_end;
for (; dir_iter != dir_end; ++dir_iter ) {
if ( boost::iends_with( boost::to_lower_copy( dir_iter->filename() ), ".xml" ) )
xml_files.push_back( dir_iter->filename() );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1857 次 |
| 最近记录: |