Sdílet prostřednictvím


basic_ostream::operator<<

Zápis do datového 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
    Ukazatele na funkci.

  • _Strbuf
    Ukazatel stream_buf objektu.

  • _Val
    Element pro zápis do datového proudu.

Vrácená hodnota

Odkaz na objekt basic_ostream.

Poznámky

<ostream> Hlavičce také definuje několik operátorů globální kurzor.Další informace naleznete v tématu operator<< (<ostream>).

První členské funkce zajišťuje, že výraz formuláře ostr <<endl volání endl**(ostr)**a potom vrátí * to.Druhý a třetí funkce zajištění jiných manipulators jako hex, se chovají podobně.Zbývající funkce jsou všechny funkce formátovaného výstupu.

Funkce

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

Extrahuje prvky z _Strbuf, _Strbuf není nulový ukazatel a vloží je.Extrakce zastaví na konec souboru, nebo pokud je extrakce generuje výjimku (což je znovu vyvolány).Zastaví také, aniž by dotyčná, vyjmutí, vložení se nezdaří-li.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 * to.

Funkce

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

Převede _Val na logickou hodnotu 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>.Vrátí funkce * to.

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 číselného pole a vložit 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>.Vrátí funkce * to.

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 číselného pole a vložit 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>.Vrátí funkce * to.

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 – třída

operator<< (<ostream>)

iostream – programování

iostreams – konvence