fork download
  1. #include <boost/program_options.hpp>
  2.  
  3. namespace po = boost::program_options;
  4.  
  5. namespace
  6. {
  7.  
  8. po::options_description desc;
  9. std::string help_string;
  10.  
  11. }
  12.  
  13. std::pair<std::string, std::string> fix_option(const std::string& value)
  14. {
  15. std::string name = value;
  16. std::string val;
  17. std::string::size_type pos = name.find("=");
  18. if (pos != std::string::npos)
  19. {
  20. val = name.substr(pos + 1);
  21. name = name.substr(0, pos);
  22. }
  23. if (name.substr(0, 2) != "--")
  24. {
  25. throw std::logic_error(std::string("invalid command, no -- in command: ") + name);
  26. }
  27. return std::make_pair(name.substr(2), val);
  28. }
  29.  
  30. int main(int argc, char* argv[])
  31. {
  32. desc.add_options()
  33. ("help", po::value<std::string>(&help_string), "produce help");
  34. po::variables_map vm;
  35. po::parsed_options allowed = po::command_line_parser(argc, argv).options(desc).
  36. extra_parser(fix_option).run();
  37. po::store(allowed, vm);
  38. po::notify(vm);
  39. std::cout << help_string << std::endl;
  40. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:37: fatal error: boost/program_options.hpp: No such file or directory
compilation terminated.
stdout
Standard output is empty