Skip to content

Latest commit

 

History

History
192 lines (133 loc) · 3.05 KB

ostream-functions.md

File metadata and controls

192 lines (133 loc) · 3.05 KB
description title ms.date f1_keywords ms.assetid helpviewer_keywords
Learn more about: <ostream> functions
<ostream> functions
11/04/2016
ostream/std::swap
ostream/std::endl
ostream/std::ends
ostream/std::flush
d6e56cc0-c8df-4dbe-be10-98e14c35ed3a
std::swap [C++]
std::endl [C++]
std::ends [C++]
std::flush [C++]

<ostream> functions

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

endl
ends
flush
swap

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

Elem
The element type.

Tr
Character traits.

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>