C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: is `\n` replacement of `std::endl`
From: Thiago Macieira (thiago_at_[hidden])
Date: 2019-07-26 11:30:40


On Thursday, 25 July 2019 19:04:00 PDT Francis Grizzly Smit via Std-Discussion
wrote:
> On 26/07/2019 11:57, praveer kumar via Std-Discussion wrote:
> > HI Experts,
> > Below is my sample code. I can see there is different time duration
> > captured to process the same data by using "\n", '\n' and std::endl.
>
> std::endl is basically equivalent to << '\n' << std::flush;

And stdout is line buffered when connected to a TTY (see setvbuf() in the C
library), so it automatically flushes on every '\n'. That means there's no
difference in behaviour.

When connected to a TTY.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups