Difficulty: Easy
Correct Answer: <<
Explanation:
Introduction:
C++ iostreams rely on operator overloading to present a clean, chainable syntax for input and output. This question asks which operator is overloaded for the output stream std::cout to send data to the console.
Given Data / Assumptions:
Concept / Approach:
The insertion operator << is overloaded for std::ostream (base of std::cout). Overloads exist for built-in types and can be provided for user-defined types by writing free functions like std::ostream& operator<<(std::ostream&, const T&). Input streams use the extraction operator >>.
Step-by-Step Solution:
1) Identify output direction: “insert into stream” uses <<.2) Note that std::cout is a std::ostream object.3) The expression std::cout << "Hello" << 42; chains multiple insertions.4) The overloaded functions return std::ostream& to enable chaining.
Verification / Alternative check:
Header
Why Other Options Are Wrong:
>>: extraction for input streams (std::cin).+: unrelated to stream output semantics.=: assignment operator; not used for printing.
Common Pitfalls:
Forgetting to make custom operator<< overloads non-members with access to internals via friends if needed.
Final Answer:
<<
Discussion & Comments