Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      operator<<,>>(std::filesystem::path)

      From cppreference.com
      <cpp‎ |filesystem‎ |path
       
       
      Filesystem library
      Classes
      Functions
      File types
       
      std::filesystem::path
      Member types
      Member constants
      Member functions
      Path decomposition
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
      Helper classes
       
      template<class CharT,class Traits>

      friendstd::basic_ostream<CharT,Traits>&

          operator<<(std::basic_ostream<CharT,Traits>& os,const path& p);
      (1)(since C++17)
      template<class CharT,class Traits>

      friendstd::basic_istream<CharT,Traits>&

          operator>>(std::basic_istream<CharT,Traits>& is, path& p);
      (2)(since C++17)

      Performs stream input or output on the pathp.std::quoted is used so that spaces do not cause truncation when later read by stream input operator.

      These function templates are not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup when std::filesystem::path is an associated class of the arguments. This prevents undesirable conversions in the presence of ausingnamespace std::filesystem;using-directive.

      Contents

      [edit]Parameters

      os - stream to perform output on
      is - stream to perform input on
      p - path to insert or extract

      [edit]Return value

      1)os
      2)is

      [edit]Exceptions

      May throw implementation-defined exceptions.

      [edit]Possible implementation

      operator<<
      template<class CharT,class Traits>friendstd::basic_ostream<CharT,Traits>&    operator<<(std::basic_ostream<CharT,Traits>& os,const path& p){    os<<std::quoted(p.string<CharT,Traits>());return os;}
      operator>>
      template<class CharT,class Traits>friendstd::basic_istream<CharT,Traits>&    operator>>(std::basic_istream<CharT,Traits>& is, path& p){std::basic_string<CharT, Traits> t;    is>>std::quoted(t);    p= t;return is;}

      [edit]Example

      Run this code
      #include <filesystem>#include <iostream> int main(){std::cout<<std::filesystem::current_path()<<'\n';std::cout<<std::filesystem::temp_directory_path()<<'\n';}

      Possible output:

      "/home/user""/tmp"

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2989C++17allowed insertion of everything convertible topath in the presence of ausing-directivemade hidden friend
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/path/operator_ltltgtgt&oldid=154690"

      [8]ページ先頭

      ©2009-2026 Movatter.jp