Victor Bazarov wrote:
Pe*******@gmail.com wrote:
>libgen.h has the basename command. But it is not a C++ head file.
Is there any C++ head file have a function or a class doing the same
thing?
Which thing is that?
basename is part of the POSIX standard. On my system, the manual page for it
says:
DIRNAME(3) Linux Programmer’s Manual
NAME
dirname, basename - Parse pathname components
SYNOPSIS
#include <libgen.h>
char *dirname(char *path);
char *basename(char *path);
DESCRIPTION
Warning: there are two different functions basename() - see below.
The functions dirname() and basename() break a null-terminated
pathname string into directory and filename components. In the
usual case, dirname() returns the string up to, but not including,
the final ’/’, and basename() returns the component following the
final ’/’. Trailing ’/’ characters are not counted as part of the
pathname.
So the answer is: There is no standard C++ function to do that. In standard
C++, there is no such thing as directories, so there no support whatsoever
for it.