Overloading Ostream Operator
Overloading Ostream Operator
+ 0 comments ostream& operator<<(ostream& out,const Person& pers){ out<<"first_name="<<pers.get_first_name()<<","<<"last_name="<<pers.get_last_name(); return out; }
+ 0 comments Here are the solution of Overloading Ostream Operator in C++ Hacker Rank Solution
+ 0 comments Here are the solution of Overloading Ostream Operator in C++ HackerRank Solution https://www.brokenprogrammers.com/overloading-ostream-operator-in-cpp-hackerrank-solution/
+ 0 comments Here is problem solution - https://thecscience.com/hackerrank-overloading-ostream-operator-in-cpp-problem-solution.html
+ 0 comments include
using namespace std;
class Person { public: Person(const string& first_name, const string& last_name) : first_name_(first_name), last_name_(last_name) {} const string& get_first_name() const { return first_name_; } const string& get_last_name() const { return last_name_; } private: string first_name_; string last_name_; }; ostream &operator<<(ostream &os,const Person &rhs){ os << "first_name=" << rhs.get_first_name() << ",last_name=" << rhs.get_last_name(); return os; }
int main() { string first_name, last_name, event; cin >> first_name >> last_name >> event; auto p = Person(first_name, last_name); cout << p << " " << event << endl; return 0; }
Sort 57 Discussions, By:
Please Login in order to post a comment