Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
To print an object directly using std::cout << obj or read from user input with std::cin >> obj, you must overload the stream insertion (<<) and stream extraction (>>) operators. Because the left-hand operand is an std::ostream (or std::istream), these cannot be member functions of your class; they must be declared as friend functions.
friend Function?A friend declaration grants a non-member function or outside class access to the private and protected members of the enclosing class.
Always return os (or is) by reference (std::ostream&). This enables standard stream chaining:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 1 questions. Each question has one correct answer.