std::experimental::filesystem::path::replace_filename - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::experimental::filesystem::path::replace_filename

From cppreference.com
< cpp‎ | experimental‎ | fs‎ | path

path& replace_filename( const path& replacement ); | (1) | (filesystem TS)

Replaces a single filename component with `replacement`. Equivalent to the following:

remove_filename();
operator/=(replacement);

### [edit] Parameters

(none)

### [edit] Return value

*this

### [edit] Exceptions

(none)

### [edit] Example

Run this code

    #include <filesystem>
    #include <iostream>

    int main()
    {
        std::cout << std::fs::path("/foo").replace_filename("bar") << '\n';
        std::cout << std::fs::path("/").replace_filename("bar") << '\n';
    }

Output:

    /bar
    bar

### [edit] See also

replace_extension | replaces the extension (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/experimental/fs/path/replace_filename&oldid=68629"