468,496 Members | 1,812 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,496 developers. It's quick & easy.

basename in C++

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?
Thanks,
Peng

Oct 5 '06 #1
4 29297
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?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 5 '06 #2
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.

Oct 5 '06 #3
"Pe*******@gmail.com" <Pe*******@gmail.comwrites:
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?
foo = basename(bar) works pretty much like:

#v+
foo = strrchr(bar, '/');
foo = foo ? foo + 1 : bar;
#v-

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
Oct 5 '06 #4
"Pe*******@gmail.com" <Pe*******@gmail.comwrites:
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?
If you're just looking for basename, you should probably use the posix
thing.

There is, however, a boost library for this stuff (filesystem). Note
that they call basename leaf, and their basename has something to do
with file extensions.

Regards,

Jens
Oct 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Xah Lee | last post: by
1 post views Thread by Sean Berry | last post: by
1 post views Thread by Wild Pete | last post: by
reply views Thread by rithish | last post: by
1 post views Thread by Peter Saffrey | last post: by
2 posts views Thread by Thomas Ploch | last post: by
reply views Thread by Salve =?iso-8859-1?Q?H=E5kedal?= | last post: by
5 posts views Thread by David d'Angers | last post: by
TheServant
6 posts views Thread by TheServant | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.