Google
 
Webcprogramming.com




An Affiliate of AIHorizon





Match word(s).

If you have any questions or comments,
please visit us on the Forums.

FAQ > What's the difference between... > std::endl vs. '\n' (C++)

This item was added on: 2003/02/19

When writing output in C++, you can use either std::endl or '\n' to produce a newline, but each has a different affect.

  • std::endl sends a newline character '\n' and flushes the output buffer.
  • '\n' sends the newline character, but does not flush the output buffer.

    The following is an example of how to use both versions, although you cannot see the flushing occuring in this example.

    
    #include <iostream> 
    
    int main(void)
    {
      std::cout <<"Testing 1" <<std::endl;
      std::cout <<"Testing 2\n";
    }
    
    /*
     * Program output:
     Testing 1
     Testing 2
    
     *
     */
    
    

    Credit: Eibro

  • Script provided by SmartCGIs.com and enhanced by Hammer.



    -----
    Interested in advertising with us?
    Please read our privacy policy.
    Copyright © 1997-2009 Cprogramming.com. All rights reserved.