basename in C++

Discussion in 'C++' started by PengYu.UT@gmail.com, Oct 5, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Oct 5, 2006
    #2
    1. Advertising

  3. Rolf Magnus Guest

    Victor Bazarov wrote:

    > 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.
    Rolf Magnus, Oct 5, 2006
    #3
  4. "" <> writes:

    > 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--
    Michal Nazarewicz, Oct 5, 2006
    #4
  5. Jens Theisen Guest

    "" <> writes:

    > 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
    Jens Theisen, Oct 5, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean Berry

    Confused on using basename...

    Sean Berry, Apr 14, 2004, in forum: Perl
    Replies:
    1
    Views:
    483
    Joe Smith
    Apr 14, 2004
  2. Ronald Fischer
    Replies:
    1
    Views:
    15,225
    Jacob
    Jul 22, 2003
  3. Xah Lee
    Replies:
    14
    Views:
    945
    Michele Dondi
    Jan 27, 2004
  4. Peter Saffrey

    basename with extensions

    Peter Saffrey, Aug 30, 2006, in forum: Python
    Replies:
    1
    Views:
    3,261
    Tal Einat
    Aug 30, 2006
  5. Thomas Ploch
    Replies:
    2
    Views:
    587
    Thomas Ploch
    Mar 14, 2007
Loading...

Share This Page