-
Book Overview & Buying
-
Table Of Contents
C++ STL Cookbook - Second Edition
By :
The path class is used throughout the filesystem library to represent a file or directory path. On POSIX-conformant systems, like macOS and Linux, the path object uses a value_type of char to represent filenames. On Windows, the value_type is wchar_t. On Windows, format() and print() 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 for this book it's messy and does not serve the purpose of simple, portable, reusable recipes.
The elegant solution is to write a formatter specialization for the path class. This allows us to display path objects simply and portably across systems.
In this recipe we'll write a formatter...