Bagikan melalui


Operator <ostream>

operator<<

operator<<

Menulis berbagai jenis ke aliran.

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

Parameter

_Ch
Karakter.

_Elem
Jenis elemen.

_Ostr
Objek basic_ostream.

Str
String karakter.

_Tr
Sifat karakter.

Val
Jenis

Tampilkan Nilai

Aliran.

Keterangan

Kelas ini basic_ostream juga mendefinisikan beberapa operator penyisipan. Untuk informasi selengkapnya, lihat basic_ostream::operator<< .

Fungsi templat

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

menentukan panjang N = traits_type::length(str) dari urutan yang dimulai pada str, dan menyisipkan urutan. Jika lebar N<_Ostr., maka fungsi juga menyisipkan pengulangan _Ostr.width - karakter isian N. Pengulangan mendahului urutan jika (_Ostr. flags & adjustfield != kiri. Jika tidak, pengulangan mengikuti urutannya. Fungsi mengembalikan _Ostr.

Fungsi templat

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

menyisipkan elemen _Ch. Jika 1 <_Ostr.width, maka fungsi juga menyisipkan pengulangan _Ostr.width - 1 karakter isian. Pengulangan mendahului urutan jika _Ostr.flags & adjustfield != left. Jika tidak, pengulangan mengikuti urutannya. Ini mengembalikan _Ostr.

Fungsi templat

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

bertempur sama seperti

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

kecuali bahwa setiap elemen _Ch urutan yang dimulai pada str dikonversi ke objek jenis Elem dengan memanggil _Ostr.put(_Ostr.widen(_Ch)).

Fungsi templat

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

bertempur sama seperti

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

kecuali bahwa _Ch dikonversi ke objek jenis Elem dengan memanggil _Ostr.put( _Ostr.widen( _Ch )).

Fungsi templat

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

bertempur sama seperti

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

(Ini tidak harus memperlebar elemen sebelum memasukkannya.)

Fungsi templat

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

bertempur sama seperti

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

(Ini tidak harus melebarkan _Ch sebelum memasukkannya.)

Fungsi templat

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

mengembalikan _Ostr << (const char *)str.

Fungsi templat

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

mengembalikan _Ostr << (char)_Ch.

Fungsi templat:

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

mengembalikan _Ostr << (const char *)str.

Fungsi templat:

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

mengembalikan _Ostr << (char)_Ch.

Fungsi templat:

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

_Ostr << val mengembalikan (dan mengonversi Referensi RValue menjadi _Ostr lvalue dalam proses).

Contoh

Lihat memerah untuk contoh menggunakan operator<<.

Lihat juga

<ostream>