getopt

Discussion in 'C++' started by Ramiro Rodriguez, Oct 14, 2003.

  1. In C there is a function to easily parse command line arguments called
    getopt. Is there such a function in c++

    RR
     
    Ramiro Rodriguez, Oct 14, 2003
    #1
    1. Advertising

  2. Ramiro Rodriguez

    Mike Wahler Guest

    "Ramiro Rodriguez" <> wrote in message
    news:p...
    > In C there is a function to easily parse command line arguments called
    > getopt.


    No there is not. Your implementation might
    provide one as an extension, but it's not
    part of standard C.

    >Is there such a function in c++


    No. If you decide to try to write one, we
    can help.

    -Mike
     
    Mike Wahler, Oct 14, 2003
    #2
    1. Advertising

  3. While it was 14/10/03 1:14 pm throughout the UK, Ramiro Rodriguez
    sprinkled little black dots on a white screen, and they fell thus:

    > In C there is a function to easily parse command line arguments called
    > getopt. Is there such a function in c++


    IINM, C++ can call any C function.

    But I'm not sure that getopt is part of standard C or C++.

    But quite recently I wrote a command line reader class that might be to
    your needs (depending on what your needs are). I'll try and get it put
    up somewhere soon.

    Stewart.

    --
    My e-mail is valid but not my primary mailbox. Please keep replies on
    on the 'group where everyone may benefit.
     
    Stewart Gordon, Oct 14, 2003
    #3
  4. Ramiro Rodriguez

    Sean Fraley Guest

    Ramiro Rodriguez wrote:

    > In C there is a function to easily parse command line arguments called
    > getopt. Is there such a function in c++
    >
    > RR


    1) getopt is part of the POSIX standard, not the ANSI C OR C++ standards.

    2) You should be able to call it from a C++ program with no problems.

    Sean
     
    Sean Fraley, Oct 15, 2003
    #4
  5. While it was 14/10/03 3:23 pm throughout the UK, Stewart Gordon
    sprinkled little black dots on a white screen, and they fell thus:

    <snip>
    > But quite recently I wrote a command line reader class that might be to
    > your needs (depending on what your needs are). I'll try and get it put
    > up somewhere soon.


    It's now up, complete with a bit of documentation (just under 8K in total):

    http://www.smjg.ableinternet.com/misc/clr.tar.gz

    Stewart.

    --
    My e-mail is valid but not my primary mailbox. Please keep replies on
    on the 'group where everyone may benefit.
     
    Stewart Gordon, Oct 15, 2003
    #5
  6. E. Robert Tisdale, Oct 16, 2003
    #6
  7. Ramiro Rodriguez wrote:
    > In C there is a function to easily parse command line arguments called
    > getopt. Is there such a function in c++


    you may want to try GNU Gengetopt that I personally maintain:

    http://www.gnu.org/software/gengetopt/

    This program generates a C function that uses getopt_long function to
    parse the command line options, to validate them and fills a struct

    I use it also inside C++ programs :)

    hope this helps
    Lorenzo

    --
    +-----------------------------------------------------+
    | Lorenzo Bettini ICQ# lbetto, 16080134 |
    | PhD in Computer Science |
    | Dip. Sistemi e Informatica, Univ. di Firenze |
    | Tel +39 055 4796741, Fax +39 055 4796730 |
    | Florence - Italy (GNU/Linux User # 158233) |
    | Home Page : http://www.lorenzobettini.it |
    | http://music.dsi.unifi.it XKlaim language |
    | http://www.lorenzobettini.it/purple Cover Band |
    | http://www.gnu.org/software/src-highlite |
    | http://www.gnu.org/software/gengetopt |
    | http://www.lorenzobettini.it/software/gengen |
    +-----------------------------------------------------+
     
    Lorenzo Bettini, Oct 17, 2003
    #7
    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. Arvind Kumar

    Problem with Getopt

    Arvind Kumar, Nov 3, 2003, in forum: Perl
    Replies:
    1
    Views:
    582
    Jim Gibson
    Nov 3, 2003
  2. dima
    Replies:
    9
    Views:
    708
    llewelly
    Sep 5, 2003
  3. Jem Berkes

    Re: Dealing with fragmented getopt parameters

    Jem Berkes, Oct 30, 2003, in forum: C Programming
    Replies:
    2
    Views:
    337
    Jem Berkes
    Oct 30, 2003
  4. Spartan815

    getopt

    Spartan815, Jan 25, 2004, in forum: C Programming
    Replies:
    2
    Views:
    1,083
    Peter Nilsson
    Jan 26, 2004
  5. =?iso-8859-1?q?Jos=E9_de_Paula?=

    Is getopt() standard C? etc.

    =?iso-8859-1?q?Jos=E9_de_Paula?=, Jan 30, 2004, in forum: C Programming
    Replies:
    14
    Views:
    648
    Randy Howard
    Feb 4, 2004
Loading...

Share This Page