Sdílet prostřednictvím


basic_ostream::operator<<

Zapisuje se do proudu.

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

Parametry

  • _Pfn
    Ukazatel na funkci.

  • _Strbuf
    Ukazatel stream_buf objektu.

  • _Val
    Prvek zapisovat do datového proudu.

Vrácená hodnota

Odkaz na objekt basic_ostream.

Poznámky

<ostream> Záhlaví definuje také několik operátorů globální kurzoru.Další informace naleznete v tématu operator<< (<ostream>).

První členské funkce zajišťuje, že výraz ve formuláři ostr << endl volání endl**(ostr)**a vrátí * Tato.Druhý a třetí funkce zajištění této druhé manipulators jako hex, se chovají podobně.Ostatní funkce jsou funkce pro všechny formátovaný výstup.

Funkce

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

Extrahuje prvky z _Strbuf, pokud _Strbuf není nulový ukazatel a vloží je.Extrakce zastaví na konec souboru, nebo pokud je extrakce vyvolá výjimku, (což je rethrown).Zastaví také, bez extrahování prvek daný vložení nezdaří.Pokud funkce vloží žádné prvky nebo pokud je extrakce vyvolá výjimku, volá funkci setstate(failbit).V každém případě vrátí funkce * Tato.

Funkce

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

Převede _Val logická pole a vloží voláním use_facet< num_put < Elem, OutIt >(getloc).put(OutIt(rdbuf), *this, getloc, val).Zde OutIt je definován jako ostreambuf_iterator< Elem, Tr >.Funkce vrátí * Tato.

Funkce

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

Každý převod _Val na číselnou pole a vložte voláním use_facet < num_put < Elem, OutIt >(getloc). put(OutIt(rdbuf), *this, getloc, val).Zde OutIt je definován jako ostreambuf_iterator < Elem, Tr >.Funkce vrátí * Tato.

Funkce

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

Každý převod _Val na číselnou pole a vložte voláním use_facet < num_put < Elem, OutIt >(getloc). put(OutIt(rdbuf), *this, getloc, val).Zde OutIt je definován jako ostreambuf_iterator < Elem, Tr >.Funkce vrátí * Tato.

Příklad

// 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;
}

Výsledek

i is cout
21
15
text in streambuf

Požadavky

Záhlaví: <ostream>

Obor názvů: std

Viz také

Referenční dokumentace

basic_ostream Class

operator<< (<ostream>)

iostream programování

iostreams konvence