简体   繁体   中英

Is there any opensource cross platform C++ library for creating menus for command line projects?

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

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";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM