cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : manipulators : endl
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
manipulators
boolalpha
dec
endl
ends
fixed
flush
hex
internal
left
noboolalpha
noshowbase
noshowpoint
noshowpos
noskipws
nounitbuf
nouppercase
oct
resetiosflags
right
scientific
setbase
setfill
setiosflags
setprecision
setw
showbase
showpoint
showpos
skipws
unitbuf
uppercase
ws

-

endl manipulator function
ostream& endl ( ostream& os ); 
<ostream>

Insert newline and flush

Inserts a new-line character.
Additionally, for buffered streams, endl flushes the buffer (i.e. writes all unwritten characters in the buffer to the output sequence, see ostream::flush).

Parameters

os
Output stream on which the insertion is performed.
Because this function is designed as a manipulator, it can be used directly with no arguments in conjunction with the insertion operator (<<) on output streams (see example).

Return Value

The same stream object on which the operation was performed (parameter os).

Example

// endl
#include <iostream>
using namespace std;

int main () {

  int a=100;
  double b=3.14;

  cout << a;
  cout << endl;              // manipulator inserted alone
  cout << b << endl << a*b;  // manipulator in concatenated insertion
  endl (cout);               // endl called as a regular global function

  return 0;
}

This example demonstrates different ways of using a manipulator.

Basic template declaration

template <class charT, class traits>
  basic_ostream<charT,traits>& endl ( basic_ostream<charT,traits>& os );

See also

flush Flush stream buffer (manipulator function)
ostream::operator<< Insert data with format (public member function)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us