目前我正在学习Boost框架,我已经发现如何列出系统中的所有文件夹和文件,使用的是
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <iostream>
using namespace std;
int main()
{
for ( boost::filesystem::recursive_directory_iterator end, dir("C:\\");
dir != end; ++dir ) {
cout << *dir << std::endl;
}
return 0;
}
但我遇到的唯一问题就是这个过程非常缓慢...... 我做错了什么还是因为 Microsoft 的 .NET 版本列出所有文件要快得多?谢谢!
std::endl
替换为\n
。std::endl
会在每次输出操作时刷新缓冲区,这可能会导致速度变慢。 - Yuushi