我使用新的动力,V1.5.3,开展这项工作就像下,由于类recursive_directory_iterator(我没有写递归code):
I'm using new boost, v1.5.3, to carry out this task like following, thanks to the class recursive_directory_iterator (I don't have to write recursive code):
void ListDirRec(const char *Dir, vector<string>& DirFileList, const char* ext) { recursive_directory_iterator rdi(Dir); recursive_directory_iterator end_rdi; DirFileList.empty(); string ext_str0(ext); for (; rdi != end_rdi; rdi++) { rdi++; //cout << (*di).path().string() << endl; cout << (*rdi).path().string() << endl; //cout << " <----- " << (*rdi).path().extension() << endl; //string ext_str1 = (*rdi).path().extension().string(); if (ext_str0pare((*rdi).path().extension().string()) == 0) { DirFileList.push_back((*rdi).path().string()); } }函数列表文件与特定扩展。此功能为案件,但经常返回断言失败错误,如:
the function list files with specific extension. This function works for cases but frequently return an "assertion fails error" like:
**** Internal program error - .... assertion (m_imp.get()) ... operations.hpp(952): dereference of end recursive_directory_iterator我刚刚想出这个错误的原因。可以在任何尝试..赶上帮助?在此先感谢您的帮助。
I barely figure out the cause of this error. Can any try.. catch help? thanks in advance for any help
推荐答案正在递增 RDI 内循环,以及在为声明:
You are incrementing rdi inside the loop as well as in the for declaration:
for (; rdi != end_rdi; rdi++) { rdi++;这意味着 RDI 可能是 end_rdi (结束迭代器,这意味着过去的最后一个元素)内你的循环。有你这样做的原因是什么? (如果这是故意的,你应该检查,以确保 RDI!= end_rdi 您增加后再次它。)
That means that rdi might be end_rdi (the end-iterator, which means past the last element) within your loop. Is there any reason you're doing this? (If this is intentional, you should check to make sure rdi != end_rdi again after you increment it.)
更多推荐
清单目录中的boost ::文件系统的文件递归
发布评论