Overloading Ostream Operator

Sort by

recency

|

66 Discussions

|

  • + 0 comments

    Is this a 'medium difficulty' problem?

  • + 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

    Shouldn't the overloaded << operator function be declared as a friend of class Person, so that it can access the private data within a Person object?

  • + 0 comments
    std::ostream &operator<<(std::ostream &out, const Person &p){
        out << "first_name=" + p.get_first_name() << "," << "last_name=" + p.get_last_name();
        
        return out;
    }
    
  • + 0 comments
    ostream &operator<<(ostream &out, const Person &obj){
        return out<<"first_name="<<obj.get_first_name()<<",last_name="<<obj.get_last_name();
    }