std::filesystem::path::stem - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::filesystem::path::stem

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

path stem() const; |  | (since C++17)

Returns the filename identified by the path stripped of its extension.

Returns the substring from the beginning of `filename()` up to and not including the last period (`.`) character.

If the filename is one of the special filesystem components dot or dot-dot, or if it has no periods, the function returns the entire `filename()`.

### [edit] Parameters

(none)

### [edit] Return value

The stem of the filename identified by the path.

### [edit] Exceptions

(none)

### [edit] Example

Run this code

    #include <iostream>
    #include <filesystem>
    namespace fs = std::filesystem;

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

        for (fs::path p = "foo.bar.baz.tar"; !p.extension().empty(); p = p.stem())
            std::cout << p.extension() << '\n';
    }

Output:

    "bar"
    ""
    ".tar"
    ".baz"
    ".bar"

### [edit] See also

filename | returns the filename path component (public member function) [edit]
extension | returns the file extension path component (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/path/stem&oldid=84903"