std::experi...::path::stem(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::experimental::filesystem::path::stem πŸ’…

okay bestie, welcome to the C++ Standard Libary corner for std::experimental::filesystem::path::stem from the filesystem TS. it’s giving β€œgive me the filename but make it de-extensioned,” and honestly? iconic. ✨


🌸 NAME 🌸

  • std::experimental::filesystem::path::stem β€” std::experimental::filesystem::path::stem
yes, the name is literally printed twice in the original. we love a dramatic entrance. πŸ’…

πŸ¦‹ Synopsis πŸ¦‹

path stem() const;  (filesystem TS)

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

The way this works: it 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().


πŸŽ€ Parameters πŸŽ€

(none) β€” literally no parameters, bestie. no args, no stress. 🫢


⭐ Return value ⭐

The stem of the filename identified by the path.

That’s the whole return value. no cap. πŸ’–


πŸ”₯ Exceptions πŸ”₯

May throw implementation-defined exceptions.

So like, it might throw, and the exact exception situation is implementation-defined β€” check with your implementation bestie, not me. 😭


🌈 Example 🌈

The original says // Run this code, so here is the code, verbatim:

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::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"

πŸ’œ See also πŸ’œ

  • filename β€” returns the filename path component (public member function)
  • extension β€” returns the file extension path component (public member function)

🫢 Category 🫢

  • Noindexed pages (original line: * Noindexed pages)

πŸ’– source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::experi...::path::stem(3) πŸ’–

πŸ“¦ where this page comes from