0

So what I need on developer side is something like

addoption("-use-something", "Use Something instead of Some other thing", localVarName, desiredValue, defauultValue);

While on user side I wish to see 3 things

  • first is to set params in if they were passed as application options/arguments (like from start my.exe -use-something )
  • second is to read user intput for "help" key word and trace all possible commands with descriptions
  • last is to read on app start up commands if some developers cin.get() is not already doing this
Rella
  • 65,003
  • 109
  • 363
  • 636

2 Answers2

2

Look at the answers of Option Parsers for C/C++?

Community
  • 1
  • 1
manol
  • 572
  • 3
  • 13
1

You should use the Boost.Program_options. Example from the tutorial:

// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
    ("help", "produce help message")
    ("compression", po::value<int>(), "set compression level")
;

po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);    

if (vm.count("help")) {
    cout << desc << "\n";
    return 1;
}

if (vm.count("compression")) {
    cout << "Compression level was set to " 
 << vm["compression"].as<int>() << ".\n";
} else {
    cout << "Compression level was not set.\n";
}
Tarantula
  • 19,031
  • 12
  • 54
  • 71