We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Overloading Ostream Operator
Overloading Ostream Operator
+ 0 comments #include <iostream> 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_; }; // Enter your code here. ostream& operator<<(ostream& os, const Person& p) { os << "first_name=" + p.get_first_name() + ",last_name=" + p.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; }
+ 0 comments // << operator overloading ostream& operator << ( ostream& out , const Person& person) { out << "first_name=" << person.get_first_name() << ",last_name=" << person.get_last_name(); return out; }
+ 0 comments std::ostream& operator<< (std::ostream& ost, const Person& person) { auto str = std::format("first_name={},last_name={} ",person.get_first_name(),person.get_last_name()); ost << str; return ost; }
+ 0 comments ostream& operator<<(ostream& os, const Person& p) { os << "first_name=" << p.get_first_name() << ",last_name=" << p.get_last_name(); return os; }
+ 0 comments ostream& operator<<(ostream& out,const Person& pers){ out<<"first_name="<<pers.get_first_name()<<","<<"last_name="<<pers.get_last_name(); return out; }
Load more conversations
Sort 61 Discussions, By:
Please Login in order to post a comment