In the last recipe, we already canonicalized/normalized paths. The filesystem::path
class is, of course, capable of more things than just holding and checking paths. It also helps us in composing paths from strings easily, and also to decompose them again.
At this point, path
does already abstract operating system details away from us, but there are also certain instances where we still need to keep such details in mind.
We will see how to deal with paths and their composition/decomposition by playing around with absolute and relative paths.
In this section, we will play around with absolute and relative paths in order to see the strengths of the path
class and the helper functions around it.
- First, we include all the necessary headers and declare that we use namespace
std
andsfilesystem
.
#include <iostream> #include <filesystem> using namespace std; using namespace filesystem;
- Then, we declare...