Compartir a través de


<ostream> functions

 

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

These are the global template functions defined in <ostream>. For member functions, see the basic_ostream Class documentation.

swap endl ends
flush

endl

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  

ends

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  

flush

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  

swap

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``).

See Also

<ostream>