我正在设计一个用c / c ++编写的快速文件读取程序,它将按照存储(创建)的顺序检索目录中的每个文件。我使用SFML和BOOST但我的程序只会以随机顺序返回文件。我想这与文件的b树排序有关?如何让BOOST按照创建顺序返回文件?
以下是代码的相关部分:
#include <string>
#include <iostream>
#include <boost/filesystem.hpp>
#include "SFML/Graphics.hpp"
using std::cout;
using namespace boost::filesystem;
using namespace std;
....
path p (argv[1]);
....
for (directory_entry& x : directory_iterator(p)){
....
fullPathName = x.path().string();
filename = x.path().filename().string();
stem = x.path().stem().string();
seqnum = stem.substr(4,5);
extn = x.path().extension().string();
cout << fullPathName << ", " << filename << ", " << stem << ", " <<
seqnum << ", " << extn <<'\n';
}
以下是示例输出:
../ take / test / snap00179.png,snap00179.png,snap00179,00179,.png ../takes/test/snap00321.png,buttle00321.png,but00001,00321,.png ../takes/test/snap00094.png,butt00094.png,butt00094,00094,.png ../takes/test/snap00121.png,hut00121.png,click00121, 00121,.png ../takes/test/snap00026.png,butk00026.png,butk00026,00026,.png ../takes/test/snap00024.png,butt00024.png,butt00024,00024,.png ../takes/test/snap00155.png,hock00155.png,buttle00155,00155,.png ../takes/test/snap00065.png,butk00065.png,butc00065,00065,.png ../takes/test/snap00015.png,butt00015.png,butt00015,00015,.png ../takes/test/snap00075.png,buttle00075.png,butc00075,00075,.png ../takes/test/snap00017.png,butk00017.png,butk00017,00017,.png