有人遇到过这个问题吗?当使用 recursive_directory_iterator 搜索分区时,当它到达末尾时会崩溃。
我在带有 boost 1.39 的 Visual Studio 2008 中得到了这个,但也在家里使用带有 boost 1.46 的 MinGW 得到了这个。我不认为我做错了什么:
#include "stdafx.h"
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
boost::filesystem::path musicPaths("d:\\");
for(boost::filesystem::recursive_directory_iterator it(musicPaths); it != boost::filesystem::recursive_directory_iterator(); ++it)
{
string strToFind = ".mp3";
boost::filesystem::path dummypath = it->path().filename();
string str = dummypath.string();
if(str.find(strToFind) != -1)
{
cout << str << endl;
}
}
return 0;
}
编辑:
我看到它最后并没有崩溃,而是当它到达系统卷信息时崩溃
最佳答案
Windows 不允许您查看“系统卷信息”目录的内部。 因此,在“系统卷信息”上释放 recursive_directory_iterator 是一个坏主意。
编辑:您也许可以使用 recursive_directory_iterator::no_push() 解决问题。来自 Boost 文档:
void no_push(bool value=true);
Requires: *this != recursive_directory_iterator().
Postcondition: no_push_pending() == value.
Throws: Nothing.
[Note: no_push() is used to prevent unwanted recursion into a directory. --end note]
关于c++ - Boost.Filesystem 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6289573/