...

/

Specialize std::formatter for the Path Class

Specialize std::formatter for the Path Class

Learn to use the specialization of std::formatter for the path class.

We'll cover the following...

The path class is used throughout the filesystem library to represent a file or directory path. On POSIX-conformant systems, such as macOS and Linux, the path object uses the char type to represent filenames. On Windows, path uses wchar_t. On Windows, cout and format() will not display primitive strings of wchar_t characters. This means there is no simple out-of-the-box way to write code that uses the filesystem library and is portable across POSIX and Windows.

We could use preprocessor directives to write specific versions of code for Windows. That may be a reasonable solution for some code bases, but ...