1 #include <iostream> 2 #include <string> 3 4 class Parse 5 { 6 private: 7 std::string str; 8 public: 9 Parse(std::string str) 10 { 11 this->str = str; 12 } 13 int getFirst() 14 { 15 return std::stoi(str); 16 } 17 int getLast() 18 is { . 19 Auto const POS = str.find_first_of ( ' - ' ); 20 is return STD :: Stoi (str.substr (+ POS . 1 )); 21 is } 22 is }; 23 is int main () 24 { 25 STD :: String S } {; 26 is STD CIN :: >> S; // user input string, such as a range, 12-45 27 parse P (S); // configured parse objects p, while parse the string S 28 STD :: COUT < <p.getFirst () << ' ' << p.getLast (); 29 return 0 ; 30 }