Correct option is A
In C++, endl is used to insert a newline and flush the output stream. It ensures that any buffered output data is written to the console or file before adding a new line. This is especially useful when immediate output is needed without relying on automatic flushing.
Important Key Points:
1.
endl is a manipulator in C++ that performs two actions:
· Inserts a newline character (\n) into the output stream.
· Flushes the stream buffer, forcing it to write any remaining data to the output device.
2. Example usage:
std::cout << "Hello" << std::endl;
3. This ensures "Hello" is displayed immediately, followed by a newline.
Knowledge Booster:
·
\n: Inserts a newline but does not flush the stream. It is faster compared to endl as it skips the flushing step.
·
flush: Only flushes the stream without adding a newline. Example:
std::cout << "Hello" << std::flush;
·
\t: Inserts a tab character, used for formatting text.
·
clear: Used to reset error flags in the stream, not related to flushing or adding a newline.
