• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <filesystem>

    std::filesystem::path::operator+=

    path& operator+=(const path& x);                   // (1)
    path& operator+=(const string_type& x);            // (2)
    path& operator+=(basic_string_view<value_type> x); // (3)
    path& operator+=(const value_type* x);             // (4)
    path& operator+=(value_type x);                    // (5)
    
    template <class Source>
    path& operator+=(const Source& x);                 // (6)
    
    template <class EcharT>
    path& operator+=(EcharT x);                        // (7)
    

    概要

    パス文字列を加算する。

    この演算子は、operator/=と違って、ディレクトリ区切り文字を自動的に挿入はせず、パス文字列への加算のみを行う。

    効果

    path(x).native()を、*thisが保持するパス文字列に加算する。

    戻り値

    *this

    #include <iostream>
    #include <filesystem>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      {
        fs::path p = "foo";
        p += "bar";
        std::cout << p << std::endl;
      }
      {
        fs::path p = "foo/";
        p += "bar";
        std::cout << p << std::endl;
      }
      {
        fs::path p = "foo";
        p += U'p'; // UTF-32文字を加算 (文字コードはクラス内部で自動変換される)
        std::cout << p << std::endl;
      }
    }
    

    出力

    "foobar"
    "foo/bar"
    "foop"
    

    バージョン

    言語

    • C++17

    処理系