1

I'm building a program that requires the inclusion of some input parameters. This is a C++ example:

int main(int argc, char *argv[]){
  if(argc == 1){
    //Run programm without any parameter
  }
  else{
    /*
    *Flags
    */
    if(!strcmp(argv[1], "-t")){
    //action t
       return 0;
    }


    if(!strcmp(argv[1], "-q")){
    //action q
       return 0;
    }
    //and soo
  }
  std::cerr << "Parameter not valid!" << std::endl;
  return 1;
}

There is a better (except for the switch) to take? Thanks :)

1 Answers1

2

You should really consider using Boost Program Options library. Next best alternative is GNU's getopt. There are also Poco's Option Processor, tclap, The Lean Mean C++ Option Parser, AnyOption and many more.