Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::filesystem::path::path

      From cppreference.com
      <cpp‎ |experimental‎ |fs‎ |path
       
       
       
      Filesystem library
      Classes
      Functions
      File types
       
      path
      Member functions
      Path decomposition
      Non-member functions
       
      path();
      (1)(filesystem TS)
      path(const path& p);
      (2)(filesystem TS)
      path( path&& p);
      (3)(filesystem TS)
      template<class Source>
      path(const Source& source);
      (4)(filesystem TS)
      template<class InputIt>
      path( InputIt first, InputIt last);
      (5)(filesystem TS)
      template<class Source>
      path(const Source& source,conststd::locale& loc);
      (6)(filesystem TS)
      template<class InputIt>
      path( InputIt first, InputIt last,conststd::locale& loc);
      (7)(filesystem TS)

      Constructs a newpath object.

      1) Constructs an empty path.
      2) Copy constructor. Constructs a copy ofp.
      3) Move constructor. Constructs a copy ofp,p is left in valid but unspecified state.
      4,5) Constructs the path from a character sequence provided bysource(4), which is a pointer or an input iterator to a null-terminated character/wide character sequence or anstd::basic_string, or represented as a pair of input iterators [first,last)(5). Any of the four character typeschar,char16_t,char32_t,wchar_t is allowed, and the method of conversion to the native character set depends on the character type used bysource.
      • If the source character type ischar, the encoding of the source is assumed to be the native narrow encoding (so no conversion takes place on POSIX systems).
      • If the source character type ischar16_t, conversion from UTF-16 to native filesystem encoding is used.
      • If the source character type ischar32_t, conversion from UTF-32 to native filesystem encoding is used.
      • If the source character type iswchar_t, the input is assumed to be the native wide encoding (so no conversion takes places on Windows).
      6,7) Constructs the path from a character sequence provided bysource(6), which is a pointer or an input iterator to a null-terminated character sequence or anstd::string, or represented as a pair of input iterators [first,last)(7). The only character type allowed ischar. Usesloc to perform the character encoding conversion. Ifvalue_type iswchar_t, converts from to wide using thestd::codecvt<wchar_t,char,std::mbstate_t> facet ofloc. Otherwise, first converts to wide using thestd::codecvt<wchar_t,char,std::mbstate_t> facet and then converts to filesystem native character type usingstd::codecvt<wchar_t, value_type> facet ofloc.

      Contents

      [edit]Parameters

      p - a path to copy
      source - astd::basic_string, pointer to a null-terminated character string, or an input iterator with a character value type that points to a null-terminated character sequence (the character type must bechar for overload(6)
      first, last - pair ofLegacyInputIterators that specify a UTF-8 encoded character sequence
      loc - locale that defines encoding conversion to use
      Type requirements
      -
      InputIt must meet the requirements ofLegacyInputIterator.
      -
      The value type ofInputIt must be one of the four character typeschar,wchar_t,char16_t andchar32_t to use the overload(5).
      -
      The value type ofInputIt must bechar to use the overload(7).

      [edit]Exceptions

      1,2) (none)
      3)
      noexcept specification:  
      noexcept
        
      4-7) (none)

      [edit]Notes

      For portable pathname generation from Unicode strings, seeu8path.

      [edit]Example

      Run this code
      #include <experimental/filesystem>#include <iostream>namespace fs= std::experimental::filesystem; int main(){    fs::path p1="/usr/lib/sendmail.cf";// portable format    fs::path p2="C:\\users\\abcdef\\AppData\\Local\\Temp\\";// native format    fs::path p3= L"D:/猫.txt";// wide string std::cout<<"p1 = "<< p1<<'\n'<<"p2 = "<< p2<<'\n'<<"p3 = "<< p3<<'\n';}

      Output:

      p1 = "/usr/lib/sendmail.cf"p2 = "C:\users\abcdef\AppData\Local\Temp\"p3 = "D:/猫.txt"

      [edit]See also

      creates apath from a UTF-8 encoded source
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/fs/path/path&oldid=157722"

      [8]ページ先頭

      ©2009-2025 Movatter.jp