std::experi...th::filename(3)

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

πŸ’– std::experi...th::filename(3) πŸ’–

okay bestie, welcome to the C++ Standard Libary manual, section 3 β€” this page is all about std::experi...th::filename, aka std::experimental::filesystem::path::filename. the way this is a whole member function just for the filename component… iconic.

🌸 NAME 🌸

std::experi...th::filename β€” std::experimental::filesystem::path::filename. that's the name, no cap.

✨ Synopsis ✨

path filename() const;  (filesystem TS)

Returns the filename component of the path.

It’s equivalent to empty() ? path() : *--end() β€” literally that expression, bestie, don’t @ me.

πŸŽ€ Parameters πŸŽ€

There are none. Zero. Nada. The page says (none), and it means it.

πŸ¦‹ Return value πŸ¦‹

The filename identified by the path. that’s it, that’s the return value.

πŸ’… Exceptions πŸ’…

May throw implementation-defined exceptions. so yeah, keep that in mind β€” implementation-defined is doing a lot of heavy lifting there.

πŸ“ Example πŸ“

// Run this code

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

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

πŸ”₯ Output πŸ”₯

"bar.txt"
".bar"
"."
"."
".."
"."
".."
"/"

πŸ‘‘ See also πŸ‘‘

  • extension β€” returns the file extension path component (public member function)
  • stem β€” returns the stem path component (public member function)
  • replace_filename β€” replaces the last path component with another path (public member function)
  • has_filename β€” checks if the corresponding path element is not empty (public member function)

🌈 Category 🌈

  • Noindexed pages

xoxo, your local Unix bestie πŸ’… β€” source: http://cppreference.com; version/date: 2024.06.10. fr fr, that’s the whole page.

πŸ“¦ where this page comes from