Joh*_*åde 18 c++ boost boost-filesystem boost-foreach
你可以使用boost :: filesystem和BOOST_FOREACH迭代目录中的所有文件吗?我试过了
path dirPath = ...
int fileCount = 0;
BOOST_FOREACH(const path& filePath, dirPath)
if(is_regular_file(filePath))
++fileCount;
Run Code Online (Sandbox Code Playgroud)
此代码编译,运行,但不会产生所需的结果.
nab*_*lke 31
您可以使用以下方式迭代目录中的文件BOOST_FOREACH:
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
namespace fs = boost::filesystem;
fs::path targetDir("/tmp");
fs::directory_iterator it(targetDir), eod;
BOOST_FOREACH(fs::path const &p, std::make_pair(it, eod))
{
if(fs::is_regular_file(p))
{
// do something with p
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15642 次 |
| 最近记录: |