##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::filesystem::path::operator=

From cppreference.com
< cpp‎ | filesystem‎ | path

path& operator=( const path& p ); | (1) | (since C++17)
path& operator=( path&& p ); | (2) | (since C++17)
template< class Source > path& operator=( const Source& source ); | (2) | (since C++17)

1) Replaces the contents of *this with a copy of the contents of `p`.
2) Replaces the contents of *this with `p`, possibly using move semantics: `p` is left in a valid, but unspecified state.
3) Replaces the contents of *this with a new path value constructed from `source` as if by overload (4) of the path constructor. Equivalent to assign(source).

### [edit] Parameters

p | - | a path to assign
source | - | a std::basic_string, std::basic_string_view, pointer to a null-terminated character/wide character string, or an input iterator that points to a null-terminated character/wide character sequence. The character type must be one of char, char16_t, char32_t, wchar_t

### [edit] Return value

*this

### [edit] Exceptions

1) (none)
2)
`noexcept` specification:
noexcept
3) (none)

### [edit] Example

Run this code

    #include <filesystem>
    namespace fs = std::filesystem;
    int main()
    {
        fs::path p = "C:/users/abcdef/AppData/Local";
        p = p / "Temp"; // move assignment
        const wchar_t* wstr = L"D:/猫.txt";
        p = wstr; // assignment from a source
    }

### [edit] See also

assign | assigns contents (public member function) [edit]
(constructor) | constructs a `path` (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/path/operator%3D&oldid=91617"
Category:

- unconditionally noexcept

Hidden categories:

- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template