std::formatterstd::filesystem::path - cppreference.com (original) (raw)

The template specialization of std::formatter for the std::filesystem::path class allows users to convert a pathname to its textual representation using formatting functions. This specialization is debug-enabled.

Contents

[edit] Format specification

The syntax of format specifications path-format-spec is:

| | | | | -------------------------------------------------------------------------- | | | | fill-and-align (optional) width (optional) ?(optional) g(optional) | | | | | | |

fill-and-align and width have the same meaning as in standard format specification.

The **?** option is used to format the pathname as an escaped string.

The **g** option is used to specify that the pathname is in generic-format representation.

[edit] Member functions

| | enables to format the pathname as an escaped string (public member function) | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | parses the format specifier as specified by path-format-spec (public member function) | | | writes the formatted output as specified by path-format-spec (public member function) |

std::formatterstd::filesystem::path::set_debug_format

| constexpr void set_debug_format(); | | | | ------------------------------------ | | |

Allows the current object to format pathname as an escaped string.

std::formatterstd::filesystem::path::parse

Parses the format specifiers as a path-format-spec and stores the parsed specifiers in the current object.

Returns an iterator past the end of the path-format-spec.

std::formatterstd::filesystem::path::format

| template< class FormatContext > auto format( const std::filesystem::path& p, FormatContext& ctx ) const -> FormatContext::iterator; | | | | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | |

Let s be p.genericstd::filesystem::path::value\_type\() if the **g** option is used, otherwise p.native(). Writes s into ctx.out() as specified by path-format-spec.

For character transcoding of the pathname:

Returns an iterator past the end of the output range.

[edit] Notes

Feature-test macro Value Std Feature
__cpp_lib_format_path 202403L (C++26) formatting support for std::filesystem::path

[edit] Example

[edit] See also

| | defines formatting rules for a given type (class template) [edit] | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |