basic_ostream::operator<<
Operacje zapisu do strumienia.
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
Wskaźnik funkcji._Strbuf
Wskaźnik do stream_buf obiektu._Val
Element do zapisu do strumienia.
Wartość zwracana
Odwołanie do obiektu basic_ostream.
Uwagi
<ostream> Nagłówka definiuje również kilka operatorów globalnego wstawiania.Aby uzyskać dodatkowe informacje, zobacz operator<< (<ostream>).
Pierwsza funkcja Członkowskie zapewnia, że wyrażenie formularza ostr <<endl wywołania endl(ostr), a następnie zwraca * to.Funkcje drugiego i trzeciego zapewnienia że inne manipulatory, takich jak hex, zachowują się podobnie.Pozostałe funkcje są wszystkie funkcje sformatowane dane wyjściowe.
Funkcja
basic_ostream<_Elem, _Tr>& operator<<(basic_streambuf<Elem, Tr> *_Strbuf);
wyodrębnia elementy z _Strbuf, jeśli _Strbuf nie jest pusty wskaźnik i wstawi je.Ekstrakcja zatrzymuje się na końcu pliku, lub jeśli Ekstrakcja zgłasza wyjątek (którą jest rethrown).Powoduje także zatrzymanie, bez wyodrębniania odnośna, jeśli to wstawka nie powiedzie się.Jeśli funkcja wstawia żadnych elementów lub jeśli Ekstrakcja zgłasza wyjątek, wywołuje funkcję setstate(failbit).W każdym przypadku, funkcja zwraca * to.
Funkcja
basic_ostream<_Elem, _Tr>& operator<<(bool _Val);
Konwertuje _Val na wartość logiczną w polu i wstawia go przez wywołanie use_facet<num_put<Elem, OutIt>(getloc).put(OutIt(rdbuf), *this, getloc, val).W tym miejscu OutIt jest zdefiniowana jako ostreambuf_iterator<Elem, Tr>.Funkcja zwraca * to.
Funkcje
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żdej konwersji _Val do liczbową w polu i wstaw go przez wywołanie use_facet<num_put<Elem, OutIt>(getloc). put(OutIt(rdbuf), *this, getloc, val).W tym miejscu OutIt jest zdefiniowana jako ostreambuf_iterator<Elem, Tr>.Funkcja zwraca * to.
Funkcje
basic_ostream<_Elem, _Tr>& operator<<(float _Val);
basic_ostream<_Elem, _Tr>& operator<<(double _Val);
basic_ostream<_Elem, _Tr>& operator<<(long double _Val);
każdej konwersji _Val do liczbową w polu i wstaw go przez wywołanie use_facet<num_put<Elem, OutIt>(getloc). put(OutIt(rdbuf), *this, getloc, val).W tym miejscu OutIt jest zdefiniowana jako ostreambuf_iterator<Elem, Tr>.Funkcja zwraca * to.
Przykład
// 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;
}
Dane wyjściowe
i is cout
21
15
text in streambuf
Wymagania
Nagłówek:<ostream>
Przestrzeń nazw: std