std::filesystem::path::concat, std::filesystem::path::operator+=

Concatenates the current path and the argument

# Declarations

path& operator+=( const path& p );

(since C++17)

path& operator+=( const string_type& str );
path& operator+=( std::basic_string_view<value_type> str );

(since C++17)

path& operator+=( const value_type* ptr );

(since C++17)

path& operator+=( value_type x );

(since C++17)

template< class CharT >
path& operator+=( CharT x );

(since C++17)

template< class Source >
path& operator+=( const Source& source );

(since C++17)

template< class Source >
path& concat( const Source& source );

(since C++17)

template< class InputIt >
path& concat( InputIt first, InputIt last );

(since C++17)

# Parameters

# Return value

*this

# Notes

Unlike with append() or operator/=, additional directory separators are never introduced.

# Example

#include <filesystem>
#include <iostream>
#include <string>
 
int main()
{
    std::filesystem::path p1; // an empty path
    p1 += "var"; // does not insert a separator
    std::cout << R"("" + "var" --> )" << p1 << '\n';
    p1 += "lib"; // does not insert a separator
    std::cout << R"("var" + "lib" --> )" << p1 << '\n';
    auto str = std::string{"1234567"};
    p1.concat(std::begin(str) + 3, std::end(str) - 1);
    std::cout << "p1.concat --> " << p1 << '\n';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 3055C++17the specification of concatenating a single character was ill-formedmade well-formed
LWG 3244C++17constraint that Source cannot be path was missingadded

# See also