C++ Sorting Filenames In A Directory
If you have access to C++17, you can use std::filesystem instead of boost::filesystem.

This is gonna cause a ton of problems by obscuring the source of names used in the code and introducing name clashes:


using namespace std;
using namespace boost::filesystem;



Qualify names from std instead, and maybe namespace fs = std::filesystem;.



Overall, the main function is very long and requires a lot of brain energy to understand.

Declaring a lot of variables at the start of a block makes the logic hard to follow:


vector &lt;string&gt; str,parsed_str;
path p("./fake_pcd");
string delimiter = ".";
string token,parsed_filename;
size_t pos = 0;
int int_filename;
vector &lt;int&gt; int_dir;



Some of the variables have sub-optimal names.  Also consider accepting the path as an argument for more flexibility:

int main(int argc, char* argv[])
{
    // validate ...
    std::path directory{std::string{argv[1]}};
    // ...
}


This is convoluted:


//insert filenames in the directory to a string vector
for (auto i = directory_iterator(p); i != directory_iterator(); i++)
{
    if (!is_directory(i-&gt;path())) //we eliminate directories in a list
    {
    str.insert(str.end(),i-&gt;path().filename().string());
    }
    else
        continue;
}



Simplification: (note that directory_iterator is a range by itself)

std::vector&lt;std::string&gt; filenames;
for (const auto&amp; entry : fs::directory_iterator{directory}) {
    if (!entry.is_directory()) {
        filenames.push_back(entry.path().filename().string());
    }
}


Sorry, I gave up trying to understand everything beyond this point.



Here's basically how I would write the same code (not tested):

#include &lt;algorithm&gt;
#include &lt;cstdlib&gt;
#include &lt;filesystem&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

namespace fs = std::filesystem;

fs::directory_entry parse_args(int argc, char* argv[])
{
    if (argc != 2) {
        std::cerr &lt;&lt; "Usage: " &lt;&lt; argv[0] &lt;&lt; " &lt;directory&gt;\n";
        std::exit(EXIT_FAILURE);
    }

    fs::directory_entry directory{argv[1]};
    if (!directory.is_directory()) {
        std::cerr &lt;&lt; '\'' &lt;&lt; argv[1] &lt;&lt; "' is not a directory\n";
        std::exit(EXIT_FAILURE);
    }
    return directory;
}

int main(int argc, char* argv[])
{
    auto directory = parse_args(argc, argv);

    std::vector&lt;fs::path&gt; filenames;
    for (const auto&amp; entry : fs::directory_iterator{directory}) {
        if (entry.is_regular_file()) {
            filenames.push_back(entry.path().filename());
        }
    }

    std::sort(filenames.begin(), filenames.end(),
              [](const auto&amp; lhs, const auto&amp; rhs) {
                  return lhs.string() &lt; rhs.string();
              });
    for (const auto&amp; file : filenames) {
        std::cout &lt;&lt; file.string() &lt;&lt; '\n';
    }
}