std::experimental::filesystem::path::filename

From cppreference.com
< cpp‎ | experimental‎ | fs‎ | path
path filename() const;
(filesystem TS)

Returns the filename identified by the path.

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

Contents

[edit] Parameters

(none)

[edit] Return value

The filename identified by the path.

[edit] Exceptions

(none)

[edit] Example

#include <filesystem>
#include <iostream>
 
int main()
{
    std::cout << std::fs::path("/foo/bar.txt").extension() << '\n';
    std::cout << std::fs::path("/foo/.bar").extension() << '\n';
    std::cout << std::fs::path("/foo/bar/").extension() << '\n';
    std::cout << std::fs::path("/foo/.").extension() << '\n';
    std::cout << std::fs::path("/foo/..").extension() << '\n';
    std::cout << std::fs::path(".").extension() << '\n';
    std::cout << std::fs::path("..").extension() << '\n';
    std::cout << std::fs::path("/").extension() << '\n';
}

Output:

bar.txt
.bar
/
 
.cc
.
..
.
..
/

[edit] See also

returns the file extension path component
(public member function)
returns the stem path component
(public member function)