Delen via


operators voor <ostream>

De <ostream> header biedt de volgende operators:

operator<<

Schrijft verschillende typen naar de stream.

template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& _Ostr,
    const Elem* str);

template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& _Ostr,
    Elem _Ch);

template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& _Ostr,
    const char* str);

template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& _Ostr,
    char _Ch);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const char* str);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _ostr,
    char _Ch);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const signed char* str);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    signed char _Ch);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const unsigned char* str);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    unsigned char _Ch);

template <class _Elem, class _Tr, class T>
basic_ostream <_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>&& _Ostr,
    Ty val);

Parameterwaarden

_Ch
Een teken.

_Elem
Het elementtype.

_Ostr
Een basic_ostream-object.

Str
Een tekenreeks.

_Tr
Karaktereigenschappen.

val-
Het type

Retourwaarde

De stroom.

Opmerkingen

De basic_ostream klasse definieert ook verschillende invoegoperators. Zie basic_ostream::operator<< voor meer informatie.

De sjabloonfunctie

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _ostr,
    const Elem *str);

bepaalt de lengte N = traits_type::lengte(str) van de reeks beginnend bij str en voegt de reeks in. Als de < N _Ostr. is, wordt met de functie ook een herhaling van _Ostr.width - N opvultekens ingevoegd. De herhaling gaat vooraf aan de reeks als (_Ostr. vlaggen & adjustfield != links. Anders volgt de herhaling de volgorde. De functie retourneert _Ostr.

De sjabloonfunctie

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    Elem _Ch);

voegt het element _Chin. Als 1 <_Ostr.width, wordt met de functie ook een herhaling van _Ostr.width - 1 opvultekens ingevoegd. De herhaling gaat vooraf aan de reeks als _Ostr.flags & adjustfield != left. Anders volgt de herhaling de volgorde. Het retourneert _Ostr.

De sjabloonfunctie

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    const char *str);

gedraagt zich hetzelfde als

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    const Elem *str);

behalve dat elk element _Ch van de reeks vanaf str wordt geconverteerd naar een object van het type Elem door _Ostr.(_Ostr.()) aan te roepen_Ch.

De sjabloonfunctie

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    char _Ch);

gedraagt zich hetzelfde als

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    Elem _Ch);

behalve dat _Ch wordt geconverteerd naar een object van het type Elem door aan te roepen _Ostr.put( _Ostr.widen( _Ch )).

De sjabloonfunctie

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const char *str);

gedraagt zich hetzelfde als

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    const Elem *str);

(De elementen hoeven niet breder te worden voordat ze worden ingevoegd.)

De sjabloonfunctie

template <class _Tr>
basic_ostream<char, Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    char _Ch);

gedraagt zich hetzelfde als

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    Elem _Ch);

(Het hoeft _Ch niet breder te maken voordat u het invoegt.)

De sjabloonfunctie

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const signed char *str);

retourneert _Ostr << (const char *)str.

De sjabloonfunctie

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    signed char _Ch);

retourneert _Ostr << (char)_Ch.

De sjabloonfunctie:

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const unsigned char *str);

retourneert _Ostr << (const char *)str.

De sjabloonfunctie:

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    unsigned char _Ch);

retourneert _Ostr << (char)_Ch.

De sjabloonfunctie:

template <class _Elem, class _Tr, class T>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<char, _Tr>&& _Ostr,
    T val);

retourneert _Ostr << val (en converteert een RValue-verwijzing naar _Ostr een lvalue in het proces).

Voorbeeld

Zie leegmaken voor een voorbeeld met behulp van operator<<.

Zie ook

<ostream>