27 Input/output library [input.output]

27.10 File systems [filesystems]

27.10.8 Class path [class.path]

27.10.8.2 path conversions [path.cvt]

27.10.8.2.1 path argument format conversions [path.fmt.cvt]

Note: The format conversions described in this section are not applied on POSIX- or Windows-based operating systems because on these systems:

  • The generic format is acceptable as a native path.

  • There is no need to distinguish between native format and generic format in function arguments.

  • Paths for regular files and paths for directories share the same syntax.

 — end note ]

Function arguments that take character sequences representing paths may use the generic pathname format grammar ([path.generic]) or the native pathname format ([fs.def.native]). If and only if such arguments are in the generic format and the generic format is not acceptable to the operating system as a native path, conversion to native format shall be performed during the processing of the argument.

Note: Some operating systems may have no unambiguous way to distinguish between native format and generic format arguments. This is by design as it simplifies use for operating systems that do not require disambiguation. An implementation for an operating system where disambiguation is required is permitted to distinguish between the formats.  — end note ]

If the native format requires paths for regular files to be formatted differently from paths for directories, the path shall be treated as a directory path if its last element is a directory-separator, otherwise it shall be treated as a path to a regular file.

27.10.8.2.2 path type and encoding conversions [path.type.cvt]

For member function arguments that take character sequences representing paths and for member functions returning strings, value type and encoding conversion is performed if the value type of the argument or return value differs from path::value_type. For the argument or return value, the method of conversion and the encoding to be converted to is determined by its value type:

  • char: The encoding is the native narrow encoding ([fs.def.native.encode]). The method of conversion, if any, is operating system dependent. [ Note: For POSIX-based operating systems path::value_type is char so no conversion from char value type arguments or to char value type return values is performed. For Windows-based operating systems, the native narrow encoding is determined by calling a Windows API function.  — end note ] [ Note: This results in behavior identical to other C and C++ standard library functions that perform file operations using narrow character strings to identify paths. Changing this behavior would be surprising and error prone.  — end note ]

  • wchar_t: The encoding is the native wide encoding ([fs.def.native.encode]). The method of conversion is unspecified. [ Note: For Windows-based operating systems path::value_type is wchar_t so no conversion from wchar_t value type arguments or to wchar_t value type return values is performed.  — end note ]

  • char16_t: The encoding is UTF-16. The method of conversion is unspecified.

  • char32_t: The encoding is UTF-32. The method of conversion is unspecified.

If the encoding being converted to has no representation for source characters, the resulting converted characters, if any, are unspecified.