Path Composition
Explore how to compose file paths in C++17 using the filesystem library's append and concat functions. Understand platform-dependent behaviors, path format conversions, and stream operators to work effectively with both POSIX and Windows systems.
We'll cover the following...
We'll cover the following...
We have two methods that allow to compose a path:
path::append()- adds a path with a directory separator.path::concat()- only adds the ‘string’ without any separator.
The functionality is also available with operators /, /= (append), + and += (concat).
For example:
However, appending a path has several rules that you have to be aware of.
For example, if the other path is absolute or the other path has a root-name, and the root-name is different from the current path root name. Then the append operation will replace this.
auto resW = fs::path{"foo"} / "D:\"; // Windows
auto resP = fs::path{"foo"} / "/bar"; // POSIX
// resW is "D:\" now
// resP is now "/bar"
In the above case resW and resP will contain the value from the second operand. As ...