[amp_mcq option1=”the ofstream class is a stream” option2=”the insertion operator works with all classes” option3=”we are actually outputting to cout” option4=”the insertion operator is overloaded in ofstream” correct=”option4″]
The correct answer is: D. the insertion operator is overloaded in ofstream.
The insertion operator << is overloaded in the ofstream class to allow it to be used to output text to an object of that class. This is done by defining a member function called operator<<() that takes a string as its argument and outputs the string to the file stream.
The other options are incorrect because:
- The ofstream class is a stream, but this is not the reason why we can output text to an object of that class using the insertion operator <<.
- The insertion operator works with all classes, but this is not the reason why we can output text to an object of the ofstream class using the insertion operator <<.
- We are not actually outputting to cout when we output text to an object of the ofstream class using the insertion operator <<.