We start this chapter with a very simple example around the std::filesystem::path
class and a helper function that intelligently normalizes filesystem paths.
The result of this recipe is a little application that takes any filesystem path and returns us the same path in normalized form. Normalized means that we get an absolute path that contains no .
or ..
path indirections.
While implementing that, we will also see what details we need to pay attention to when working with this basic part of the filesystem library.
In this section, we will implement a program that just accepts a filesystem path as a command-line argument and then prints it in normalized form.
- Includes come first, and then we declare that we use namespace
std
andfilesystem
.
#include <iostream> #include <filesystem> using namespace std; using namespace filesystem;
- In the main function, we check whether the user provided a command-line argument...