<ostream> functions

Visual Studio 2015
 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at <ostream> functions.

swap](#swap)|endl|ends|
|flush|

Terminates a line and flushes the buffer.

template class<_Elem, _Tr> basic_ostream<_Elem, _Tr>& endl(basic_ostream<_Elem, _Tr>& _Ostr);

Parameters

_Elem
The element type.

_Ostr
An object of type basic_ostream.

_Tr
Character traits.

Return Value

An object of type basic_ostream.

Remarks

The manipulator calls _Ostr.put( _Ostr. widen( '\n')), and then calls _Ostr.flush. It returns _Ostr.

Example

// ostream_endl.cpp  
// compile with: /EHsc  
#include <iostream>  
  
int main( )   
{  
   using namespace std;  
   cout << "testing" << endl;  
}  

testing  

Terminates a string.

    template class<_Elem, _Tr> basic_ostream<_Elem, _Tr>& ends(basic_ostream<_Elem, _Tr>& _Ostr);

Parameters

_Elem
The element type.

_Ostr
An object of type basic_ostream.

_Tr
Character traits.

Return Value

An object of type basic_ostream.

Remarks

The manipulator calls _Ostr.put( _Elem( '\0')). It returns _Ostr.

Example

// ostream_ends.cpp  
// compile with: /EHsc  
#include <iostream>  
  
int main( )   
{  
   using namespace std;  
   cout << "a";  
   cout << "b" << ends;  
   cout << "c" << endl;  
}  

ab c  

Flushes the buffer.

template class<_Elem, _Tr> basic_ostream<_Elem, _Tr>& flush(basic_ostream<_Elem, _Tr>& _Ostr);

Parameters

_Elem
The element type.

_Ostr
An object of type basic_ostream.

_Tr
Character traits.

Return Value

An object of type basic_ostream.

Remarks

The manipulator calls _Ostr.flush. It returns _Ostr.

Example

// ostream_flush.cpp  
// compile with: /EHsc  
#include <iostream>  
  
int main( )   
{  
   using namespace std;  
   cout << "testing" << flush;  
}  

testing  

Exchanges the values of two basic_ostream objects.

template <class Elem, class Tr>  
void swap(
    basic_ostream<Elem, Tr>& left,  
    basic_ostream<Elem, Tr>& right);

Parameters

left
An lvalue reference to a basic_ostream object.

right
An lvalue reference to a basic_ostream object.

Remarks

The template function swap executes left.swap(`` right``).

<ostream>

Show: