fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. struct UI
  6. {
  7. UI( const std::vector<std::string>& menuwords,
  8. const std::string& either_header_or_footer, bool is_header ) ;
  9.  
  10. void display() const ;
  11.  
  12. // ...
  13.  
  14. std::vector<std::string> menuarray ;
  15. std::string header_or_footer ;
  16. bool head ;
  17. bool foot ;
  18.  
  19. std::size_t place = 0 ;
  20. };
  21.  
  22. UI::UI( const std::vector<std::string>& menuwords,
  23. const std::string& either_header_or_footer, bool is_header )
  24. : menuarray(menuwords), header_or_footer(either_header_or_footer)
  25. { head = is_header ; foot = !is_header ; }
  26.  
  27. void UI::display() const
  28. {
  29. for( std::size_t i = 0 ; i < menuarray.size() ; ++i )
  30. {
  31. if( i == place ) std::cout << '>' ;
  32. else std::cout << ' ' ;
  33. std::cout << menuarray[i] << '\n' ;
  34. }
  35. }
  36.  
  37. int main()
  38. {
  39. std::vector<std::string> menuwords { "zero", "one", "two", "three", "four" } ;
  40. UI ui( menuwords, "this is a header", true ) ;
  41. ui.display() ;
  42.  
  43. std::cout << "---------\n" ;
  44. ui.place = 2 ;
  45. ui.display() ;
  46. }
  47.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
>zero
 one
 two
 three
 four
---------
 zero
 one
>two
 three
 four