Thread: jumping into C++ and menu options from cli (argc,argv)

  1. #1
    Banned
    Join Date
    Aug 2017
    Posts
    861

    jumping into C++ and menu options from cli (argc,argv)

    first off if there is a better way then what i am suggesting, please feel free to inform me.

    I am looking into a menu system to use in C++, I found this page, How to parse command line parameters. - C++ Articles

    but upon trying the code within it, under the heading, "More on usage messages" , of course it fails. It too suggests getopts which I have dealt with in C. But I am wondering if their are other options beside that and the "old way" that is always shown in the how to books, on menu creation. An example of that is from in here even.

    Help with chapter 6 (functions) practice problem 1

    not wanting to create a long list of
    Code:
     
    if  ( strcmp(argv[i], whatever)
    {
      var = whatever;
    }
      else if (strcmp(argv[i], whatever)
    {
      var = whatever;
    }
    else
    {
    whatever;
    }
    or
    Code:
    if ( var == "string" ) 
    ....
    else if ( var == "string || var == "string")
    type statements (inside a loop).

    Just hoping someone knows a few more options that are not too hard to pick up on to use. of course using the long and short options format 1 hyphen (-) two hyphens (--) setup. or as requested if someone got a better Idea I am open to suggestions.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    There isn't any other way that I know of. getopt and getopt_long are the best for parsing the command line. You could use boost to do something quite similar but that's like using a sledgehammer to crack a walnut...
    Last edited by GReaper; 09-28-2017 at 01:28 AM.
    Devoted my life to programming...

  3. #3
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by GReaper View Post
    There isn't any other way that I know of. getopt and getopt_long are the best for parsing the command line. You could use boost to do something quite similar but that's like using a sledgehammer to crack a walnut...
    thanks, now it is a matter of is it worth taking my C program and just rewriting it as a C++ program or not. because I still cannot think of it using classes or objects to enhance the performance of what it is already doing in C. I just wanted to give C++ a try without just doing them silly but useful (for ones that need to) assignments in a book on C++.

    Maybe taking my struct 's and turning them into classes, maybe.
    Last edited by userxbw; 09-28-2017 at 08:02 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using argc and argv[]
    By hewlettuser in forum C++ Programming
    Replies: 6
    Last Post: 03-18-2017, 11:18 PM
  2. argc & argv
    By miryellis in forum C Programming
    Replies: 11
    Last Post: 09-19-2004, 11:59 PM
  3. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 10:17 AM
  4. argc,argv
    By thanatos in forum C Programming
    Replies: 5
    Last Post: 05-31-2002, 01:26 AM
  5. argc and argv
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2002, 05:21 PM

Tags for this Thread