basic_ostream::operator<<

Escribe en la secuencia.

basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& (*_Pfn)(basic_ostream<_Elem, _Tr>&)
);
basic_ostream<_Elem, _Tr>& operator<<(
    ios_base& (*_Pfn)(ios_base&)
);
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ios<_Elem, _Tr>& (*_Pfn)(basic_ios<_Elem, _Tr>&)
);
basic_ostream<_Elem, _Tr>& operator<<(
    basic_streambuf<_Elem, _Tr> *_Strbuf
);
basic_ostream<_Elem, _Tr>& operator<<(
    bool _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    short _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    unsigned short _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    int __w64 _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    unsigned int __w64 _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    long _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    unsigned long __w64 _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
     long long _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
     unsigned long long _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    float _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    double _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    long double _Val
);
basic_ostream<_Elem, _Tr>& operator<<(
    const void *_Val
);

Parámetros

  • _Pfn
    Puntero a una función.

  • _Strbuf
    un puntero a un objeto de stream_buf .

  • _Val
    Un elemento a escribir en la secuencia.

Valor devuelto

Una referencia al objeto de basic_ostream.

Comentarios

El encabezado de <ostream> también define varios operadores globales de inserción.Para obtener más información, vea operator<< (<ostream>).

La primera función miembro garantiza que una expresión de formulario endl de ostr << llama endl(ostr), y devuelve *this.La segunda y tercera funciones garantizan que otros manipuladores, como Hexadecimal, se comporten de forma similar.Restantes las funciones son todas funciones con formato de salida.

la función

basic_ostream<_Elem, _Tr>& operator<<(basic_streambuf<Elem, Tr> *_Strbuf);

extrae elementos de _Strbuf, si _Strbuf no es un puntero NULL, y los inserta.La recuperación se detiene en final de archivo, o si una recuperación produce una excepción (que se reinician).También detiene, sin extraer el elemento en cuestión, si se produce una inserción.Si la función no inserta ningún elemento, o si una recuperación produce una excepción, la función setstate(failbit).En cualquier caso, la función devuelve *this.

la función

basic_ostream<_Elem, _Tr>& operator<<(bool _Val);

convierte _Val a un campo booleano y se inserta llamando a use_facet <num_put<Elem, OutIt> (getloc).título(OutIt(rdbuf), *this, getloc, val).Aquí, OutIt se define como ostreambuf_iterator <Elem, Tr> .la función devuelve *this.

las funciones

basic_ostream<_Elem, _Tr>& operator<<(short _Val);
basic_ostream<_Elem, _Tr>& operator<<(unsigned short _Val);
basic_ostream<_Elem, _Tr>& operator<<(int _Val);
basic_ostream<_Elem, _Tr>& operator<<(unsigned int __w64 _Val);
basic_ostream<_Elem, _Tr>& operator<<(long _Val);
basic_ostream<_Elem, _Tr>& operator<<(unsigned long _Val);
basic_ostream<_Elem, _Tr>& operator<<(long long _Val);
basic_ostream<_Elem, _Tr>& operator<<(unsigned long long _Val);
basic_ostream<_Elem, _Tr>& operator<<(const void *_Val);

cada convertido _Val a un campo numérico y se inserta llamando a use_facet <num_put<Elem, OutIt> (getloc). título(OutIt(rdbuf), *this, getloc, val).Aquí, OutIt se define como ostreambuf_iterator <Elem, Tr> .la función devuelve *this.

las funciones

basic_ostream<_Elem, _Tr>& operator<<(float _Val);
basic_ostream<_Elem, _Tr>& operator<<(double _Val);
basic_ostream<_Elem, _Tr>& operator<<(long double _Val);

cada _Val convert a un campo numérico y se inserta llamando a use_facet <num_put<Elem, OutIt> (getloc). título(OutIt(rdbuf), *this, getloc, val).Aquí, OutIt se define como ostreambuf_iterator <Elem, Tr> .la función devuelve *this.

Ejemplo

// basic_ostream_op_write.cpp
// compile with: /EHsc
#include <iostream>
#include <string.h>

using namespace std;

ios_base& hex2( ios_base& ib )
{
   ib.unsetf( ios_base::dec );
   ib.setf( ios_base::hex );
   return ib;
}

basic_ostream<char, char_traits<char> >& somefunc(basic_ostream<char, char_traits<char> > &i)
{
   if ( i == cout )
   {
      i << "i is cout" << endl;
   }
   return i;
}

class CTxtStreambuf : public basic_streambuf< char, char_traits< char > >
{
public:
   CTxtStreambuf(char *_pszText)
   {
      pszText = _pszText;
      setg(pszText, pszText, pszText+strlen(pszText));
   };
          char *pszText;
};

int main( )
{
   cout << somefunc;
   cout << 21 << endl;

   hex2(cout);
   cout << 21 << endl;

   CTxtStreambuf f("text in streambuf");
   cout << &f << endl;
}

Output

i is cout
21
15
text in streambuf

Requisitos

encabezado: <ostream>

espacio de nombres: std

Vea también

Referencia

basic_ostream Class

operator<< (<ostream>)

programación iostream

convenciones de iostreams