std::filesystem::path::stem

Returns the filename identified by the generic-format path stripped of its extension.

# Declarations

path stem() const;

(since C++17)

# Return value

The stem of the filename identified by the path (i.e. the filename without the final extension).

# Example

#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
 
int main()
{
    for (const fs::path p : {"/foo/bar.txt", "/foo/.bar", "foo.bar.baz.tar"})
        std::cout << "path: " << p << ", stem: " << p.stem() << '\n';
 
    std::cout << '\n';
 
    for (fs::path p = "foo.bar.baz.tar"; !p.extension().empty(); p = p.stem())
        std::cout << "path: " << p << ", extension: " << p.extension() << '\n';
}

# See also