hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    Which of the following is used in C++ to flush a stream and add a newline?
    Question



    Which of the following is used in C++ to flush a stream and add a newline?

    A.

    endl

    B.

    \n

    C.

    flush

    D.

    \t

    E.

    clear

    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.

    Free Tests

    Free
    Must Attempt

    SBI Clerk Prelims Full Mock Test-01

    languageIcon English
    • pdpQsnIcon100 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    Free
    Must Attempt

    SBI Clerk Prelims 2026 : Reasoning Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt

    SBI Clerk Prelims 2026 : Quantitative Aptitude Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    test-prime-package

    Access ‘SEBI Grade-A Assistant Manager’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    446k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow