Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef NAME_H
- #define NAME_H
- #include <string>
- #include <iostream>
- class Name{
- public:
- explicit Name(const std::string& first = "Homer",const std:: string& last = "Simpson"):first_(first),last_(last){}
- friend std::ostream& operator<<(std::ostream&, const Name&);
- friend std::istream& operator>>(std::istream&, Name&);
- friend bool operator ==(const Name & lhs, const Name& rhs);
- std::string getFirst(){ return first_;}
- std::string getLast(){return last_;}
- private:
- std::string first_;
- std::string last_;
- };
- inline std::ostream& operator<<(std::ostream& os, const Name& n){
- return os << n.first_<< " " << n.last_;
- }
- inline std::istream& operator>>(std::istream& is, Name& n){
- std::string first,last;
- if(is >> first >> last ){
- n.first_ = first;
- n.last_ = last;
- }
- else
- is.setstate(std::ios_base::failbit);
- return is;
- }
- inline bool operator ==(const Name & lhs, const Name& rhs)
- {
- return lhs.last_ == rhs.last_ && lhs.first_ == rhs.first_;
- }
- #endif
Add Comment
Please, Sign In to add comment