Advertisement
Guest User

Untitled

a guest
May 28th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. cmake_minimum_required(VERSION 3.10)
  2. #project(Radio)
  3.  
  4. FIND_PACKAGE( Boost 1.40 COMPONENTS program_options REQUIRED )
  5. INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
  6.  
  7.  
  8. add_executable(zadanie2 client.cpp)
  9.  
  10. TARGET_LINK_LIBRARIES( zadanie2 LINK_PUBLIC ${Boost_LIBRARIES} )
  11.  
  12.  
  13.  
  14.  
  15.  
  16. #include <boost/program_options.hpp>
  17. #include <iostream>
  18.  
  19. using namespace boost::program_options;
  20.  
  21. void on_age(int age)
  22. {
  23. std::cout << "On age: " << age << '\n';
  24. }
  25.  
  26. int main(int argc, const char *argv[])
  27. {
  28. try
  29. {
  30. options_description desc{"Options"};
  31. desc.add_options()
  32. ("help,h", "Help screen")
  33. ("pi,p", value<float>()->default_value(3.14f), "Pi")
  34. ("age", value<int>()->notifier(on_age), "Age");
  35.  
  36. variables_map vm;
  37. store(parse_command_line(argc, argv, desc), vm);
  38. notify(vm);
  39.  
  40. if (vm.count("help"))
  41. std::cout << desc << '\n';
  42. else if (vm.count("age"))
  43. std::cout << "Age: " << vm["age"].as<int>() << '\n';
  44. else if (vm.count("pi"))
  45. std::cout << "Pi: " << vm["pi"].as<float>() << '\n';
  46. }
  47. catch (const error &ex)
  48. {
  49. std::cerr << ex.what() << '\n';
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement