I am trying to get filenames in a directory "in order". I tried with c++ std::filesystem::directory_iterator to do so. As mentioned in https://en.cppreference.com/w/cpp/filesystem/directory_iterator it provides all filenames in the directory, excluding "." and ".." operator but not in order.
Kindly do help me out, Thanks in advance.
Here is the simple code i used
#include <iostream>
#include <string>
#include <experimental/filesystem>
#include <vector>
int main
{
// path to cereal folder
std::string path_to_cereal_folder = "/home/ros2/Documents";
for (auto& entry : std::experimental::filesystem::directory_iterator(path_to_cereal_folder) )
{
std::cout << entry.path() << std::endl;
}
return 0;
}