std::experi...::path::stem(3)
π
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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms