#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    26
    Rep Power
    0

    Using endl in C++


    So i am reading C++ primer and i saw that at the end of cout
    they us endl i know its for flushing the buffer but is it needed.
    Because in C the you flush the buffer input so a standard input function doesnt read the /n but do you need to do it in C++.

    Thanks in advance.
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,109
    Rep Power
    1802
    Originally Posted by CAAA
    i know its for flushing the buffer but is it needed.
    It is not for flushing the buffer, but rather for outputing a new line. It happens to also flush the buffer.

    Whether it is necessary is system dependent, but since by default cout is synchronised with stdout and is almost certainly implemented using stdio, then if on your system you don't get output without flushing, but you don't want to output a newline, then you will need to independently flush the buffer. If you want the code to be system independent and portable, you should do that in any case.

    Code:
    std::cout << "Hello, World" << std::flush ;
    Last edited by clifford; August 7th, 2013 at 02:24 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    26
    Rep Power
    0
    Thanks just wasnt sure if it was needed well now i know thanks to you.

IMN logo majestic logo threadwatch logo seochat tools logo