[fs.path.cvt]

# 31 Input/output library [[input.output]](./#input.output)

## 31.12 File systems [[filesystems]](filesystems#fs.path.cvt)

### 31.12.6 Class path [[fs.class.path]](fs.class.path#fs.path.cvt)

#### 31.12.6.3 Conversions [fs.path.cvt]

#### [31.12.6.3.1](#fs.path.fmt.cvt) Argument format conversions [[fs.path.fmt.cvt]](fs.path.fmt.cvt)

[1](#fs.path.fmt.cvt-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13935)

[*Note [1](#fs.path.fmt.cvt-note-1)*:

The format conversions described in this subclause
are not applied on POSIX-based operating systems
because on these systems:

- [(1.1)](#fs.path.fmt.cvt-1.1)

  The generic format is acceptable as a native path[.](#fs.path.fmt.cvt-1.1.sentence-1)

- [(1.2)](#fs.path.fmt.cvt-1.2)

  There is no need to distinguish between native format and generic format in function arguments[.](#fs.path.fmt.cvt-1.2.sentence-1)

- [(1.3)](#fs.path.fmt.cvt-1.3)

  Paths for regular files and paths for directories share the same syntax[.](#fs.path.fmt.cvt-1.3.sentence-1)

â *end note*]

[2](#fs.path.fmt.cvt-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13947)

Several functions are defined to accept [*detected-format*](#def:detected-format) arguments,
which are character sequences[.](#fs.path.fmt.cvt-2.sentence-1)

A detected-format argument represents a path
using either a pathname in the generic format ([[fs.path.generic]](fs.path.generic "31.12.6.2 Generic pathname format"))
or a pathname in the native format ([[fs.class.path]](fs.class.path "31.12.6 Class path"))[.](#fs.path.fmt.cvt-2.sentence-2)

Such an argument is taken to be in the generic format if and only if
it matches the generic format and is not acceptable to the operating system
as a native path[.](#fs.path.fmt.cvt-2.sentence-3)

[3](#fs.path.fmt.cvt-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13956)

[*Note [2](#fs.path.fmt.cvt-note-2)*:

Some operating systems have no unambiguous way to distinguish between native format and generic format arguments[.](#fs.path.fmt.cvt-3.sentence-1)

This is by design as it simplifies use for operating systems that do not require
disambiguation[.](#fs.path.fmt.cvt-3.sentence-2)

It is possible that an implementation for an operating system
where disambiguation is needed distinguishes between the formats[.](#fs.path.fmt.cvt-3.sentence-3)

â *end note*]

[4](#fs.path.fmt.cvt-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13964)

Pathnames are converted as needed between the generic and native formats
in an operating-system-dependent manner[.](#fs.path.fmt.cvt-4.sentence-1)

Let *G(n)* and *N(g)* in a mathematical sense
be the implementation's functions that convert native-to-generic
and generic-to-native formats respectively[.](#fs.path.fmt.cvt-4.sentence-2)

If *g=G(n)* for some *n*, then *G(N(g))=g*;
if *n=N(g)* for some *g*, then *N(G(n))=n*[.](#fs.path.fmt.cvt-4.sentence-3)

[*Note [3](#fs.path.fmt.cvt-note-3)*:

Neither *G* nor *N* need be invertible[.](#fs.path.fmt.cvt-4.sentence-4)

â *end note*]

[5](#fs.path.fmt.cvt-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13976)

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*](fs.path.generic#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]"),
otherwise it shall be treated as a path to a regular file[.](#fs.path.fmt.cvt-5.sentence-1)

[6](#fs.path.fmt.cvt-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13982)

[*Note [4](#fs.path.fmt.cvt-note-4)*:

A path stores a native format pathname ([[fs.path.native.obs]](fs.path.native.obs "31.12.6.5.6 Native format observers"))
and acts as if it also stores a generic format pathname,
related as given below[.](#fs.path.fmt.cvt-6.sentence-1)

The implementation can generate the generic format pathname
based on the native format pathname (and possibly other information)
when requested[.](#fs.path.fmt.cvt-6.sentence-2)

â *end note*]

[7](#fs.path.fmt.cvt-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13992)

When a path is constructed from or is assigned a single representation
separate from any path, the other representation is selected
by the appropriate conversion function (*G* or *N*)[.](#fs.path.fmt.cvt-7.sentence-1)

[8](#fs.path.fmt.cvt-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13997)

When the (new) value *p* of one representation of a path
is derived from the representation of that or another path,
a value *q* is chosen for the other representation[.](#fs.path.fmt.cvt-8.sentence-1)

The value *q* converts to *p* (by *G* or *N* as appropriate)
if any such value does so;*q* is otherwise unspecified[.](#fs.path.fmt.cvt-8.sentence-2)

[*Note [5](#fs.path.fmt.cvt-note-5)*:

If *q* is the result of converting any path at all,
it is the result of converting *p*[.](#fs.path.fmt.cvt-8.sentence-3)

â *end note*]

#### [31.12.6.3.2](#fs.path.type.cvt) Type and encoding conversions [[fs.path.type.cvt]](fs.path.type.cvt)

[1](#fs.path.type.cvt-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14013)

The [*native encoding*](#def:native_encoding "31.12.6.3.2 Type and encoding conversions [fs.path.type.cvt]") of an ordinary character string is
the operating system dependent current encoding
for pathnames ([[fs.class.path]](fs.class.path "31.12.6 Class path"))[.](#fs.path.type.cvt-1.sentence-1)

The [*native encoding*](#def:native_encoding "31.12.6.3.2 Type and encoding conversions [fs.path.type.cvt]") for wide character strings is
the implementation-defined execution
wide-character set encoding ([[character.seq]](character.seq "16.3.3.3.4 Character sequences"))[.](#fs.path.type.cvt-1.sentence-2)

[2](#fs.path.type.cvt-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14021)

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 frompath​::​value_type[.](#fs.path.type.cvt-2.sentence-1)

For the argument or return value, the method of conversion and the encoding
to be converted to is determined
by its value type:

- [(2.1)](#fs.path.type.cvt-2.1)

  char: The encoding is the native ordinary encoding[.](#fs.path.type.cvt-2.1.sentence-1)
  The method of conversion, if any, is operating system dependent[.](#fs.path.type.cvt-2.1.sentence-2)
  [*Note [1](#fs.path.type.cvt-note-1)*:
  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[.](#fs.path.type.cvt-2.1.sentence-3)
  For Windows-based operating systems, the
native ordinary encoding is determined by calling a Windows API function[.](#fs.path.type.cvt-2.1.sentence-4)
 â *end note*]
  [*Note [2](#fs.path.type.cvt-note-2)*:
  This results in behavior identical to other C and C++
standard library functions that perform file operations using ordinary character
strings to identify paths[.](#fs.path.type.cvt-2.1.sentence-5)
  Changing this behavior would be surprising and
error-prone[.](#fs.path.type.cvt-2.1.sentence-6)
 â *end note*]

- [(2.2)](#fs.path.type.cvt-2.2)

  wchar_t: The encoding is the native wide encoding[.](#fs.path.type.cvt-2.2.sentence-1)
  The method of conversion is unspecified[.](#fs.path.type.cvt-2.2.sentence-2)
  [*Note [3](#fs.path.type.cvt-note-3)*:
  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[.](#fs.path.type.cvt-2.2.sentence-3)
 â *end note*]

- [(2.3)](#fs.path.type.cvt-2.3)

  char8_t: The encoding is UTF-8[.](#fs.path.type.cvt-2.3.sentence-1)
  The method of conversion
is unspecified[.](#fs.path.type.cvt-2.3.sentence-2)

- [(2.4)](#fs.path.type.cvt-2.4)

  char16_t: The encoding is UTF-16[.](#fs.path.type.cvt-2.4.sentence-1)
  The method of conversion
is unspecified[.](#fs.path.type.cvt-2.4.sentence-2)

- [(2.5)](#fs.path.type.cvt-2.5)

  char32_t: The encoding is UTF-32[.](#fs.path.type.cvt-2.5.sentence-1)
  The method of conversion
is unspecified[.](#fs.path.type.cvt-2.5.sentence-2)

[3](#fs.path.type.cvt-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14066)

If the encoding being converted to has no representation for source
characters, the resulting converted characters, if any, are unspecified[.](#fs.path.type.cvt-3.sentence-1)

Implementations should not modify member function arguments
if already of type path​::​value_type[.](#fs.path.type.cvt-3.sentence-2)
