DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Endl vs \n

  1. #1
    Join Date
    Oct 2021
    Location
    Pune
    Posts
    1

    Question Endl vs \n

    Once I tried submitting a code on some coding platform my code gave TLE when I used endl but it passed the same code using \n can any one tell me what is the difference between endl and \n?

  2. #2
    Join Date
    Jun 2012
    Location
    Largo, FL.
    Posts
    35
    Did you GOOGLE-> Endl vs \n

    and see all of the articles?

  3. #3
    Join Date
    Jan 2018
    Posts
    42
    endl does a stream flush before inserting new-line. '\n' just inserts the new-line with no flush. When writing to streams such as file, this can have a major performance impact. Unless you really need a stream flush, just use '\n'. You used to need a stream flush before input from the same stream (especially for screen(stdout)/keyboard(stdin). However these are now tied and work together so normally a screen flush isn't explicitly required before keyboard input.
    C++20 Compiler: Microsoft VS2022 (17.0.2)

  4. #4
    Join Date
    Oct 2021
    Location
    Bangalore
    Posts
    1
    Actually I also faced this issue when I started programming and happened to read an article where they have explained the same:
    Endl in C++ is a manipulator or in simple terms a command. So when endl is encountered, the operating system will flush the output buffer and insert a new line while \n in C++ is a character taking 1 byte of memory and is appended to the existing bytes in the output buffer.

    Whenever the buffer is flushed, this 1 byte of memory corresponding to \n will result in a new line in the final display of bytes to the standard output.

Similar Threads

  1. overloading << does not take endl !
    By suneel in forum C++
    Replies: 5
    Last Post: 05-21-2008, 04:32 AM
  2. Re: endl manipulator-Dannys addendum
    By Suresh in forum C++
    Replies: 2
    Last Post: 07-02-2001, 12:29 PM
  3. endl manipulator
    By Suresh in forum C++
    Replies: 6
    Last Post: 06-29-2001, 01:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center