A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../filesystem/path/filename.html below:

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

path filename() const;

(since C++17)

Returns the generic-format filename component of the path.

Equivalent to relative_path().empty() ? path() : *--end().

[edit] Parameters

(none)

[edit] Return value

The filename identified by the path.

[edit] Exceptions

May throw implementation-defined exceptions.

[edit] Example
#include <filesystem>
#include <iostream>
namespace fs = std::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'
              << fs::path("//host").filename() << '\n';
}

Output:

"bar.txt"
".bar"
""
"."
".."
"."
".."
""
"host"
[edit] See also returns the file extension path component
(public member function) [edit] returns the stem path component (filename without the final extension)
(public member function) [edit] replaces the last path component with another path
(public member function) [edit] checks if the corresponding path element is not empty
(public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4