Guest User

Untitled

a guest
Jul 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #ifndef NAME_H
  2. #define NAME_H
  3. #include <string>
  4. #include <iostream>
  5. class Name{
  6. public:
  7. explicit Name(const std::string& first = "Homer",const std:: string& last = "Simpson"):first_(first),last_(last){}
  8. friend std::ostream& operator<<(std::ostream&, const Name&);
  9. friend std::istream& operator>>(std::istream&, Name&);
  10. friend bool operator ==(const Name & lhs, const Name& rhs);
  11.  
  12. std::string getFirst(){ return first_;}
  13. std::string getLast(){return last_;}
  14. private:
  15. std::string first_;
  16. std::string last_;
  17. };
  18.  
  19. inline std::ostream& operator<<(std::ostream& os, const Name& n){
  20. return os << n.first_<< " " << n.last_;
  21. }
  22. inline std::istream& operator>>(std::istream& is, Name& n){
  23. std::string first,last;
  24. if(is >> first >> last ){
  25. n.first_ = first;
  26. n.last_ = last;
  27. }
  28. else
  29. is.setstate(std::ios_base::failbit);
  30. return is;
  31. }
  32. inline bool operator ==(const Name & lhs, const Name& rhs)
  33. {
  34. return lhs.last_ == rhs.last_ && lhs.first_ == rhs.first_;
  35. }
  36. #endif
Add Comment
Please, Sign In to add comment