Muokkaa

Jaa


<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>