Guest User

Untitled

a guest
Jan 17th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1.  
  2.     #ifndef PARSER_H
  3.     #define PARSER_H
  4.  
  5.     #include <iostream>
  6.     #include <sstream>
  7.  
  8.    
  9.  
  10.     template <class T>
  11.     class Parser {
  12.     private:
  13.         std::istream& _in;
  14.         std::string _stopLine;
  15.         std::string currentString;
  16.  
  17.     public:
  18.         Parser(std::istream& in, std::string stopLine) :
  19.             _in(in), _stopLine(stopLine)
  20.         {
  21.         }
  22.  
  23.         inline bool readNext(T& element)
  24.         {
  25.             std::cin >> element;
  26.             std::stringstream stream;
  27.             stream << element;
  28.             stream >> currentString;
  29.  
  30.                 if (currentString != _stopLine)
  31.                 {
  32.                     return true;
  33.                 }
  34.                
  35.                
  36.                     return false;
  37.                
  38.            
  39.         }
  40.  
  41.     };
  42.    
  43.  
  44.  
  45.  
  46. #endif //!PARSER_H
Add Comment
Please, Sign In to add comment