다음을 통해 공유


basic_ostream::operator<<

스트림에 씁니다.

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

매개 변수

  • _Pfn
    함수 포인터입니다.

  • _Strbuf
    A pointer to a stream_buf object.

  • _Val
    An element to write to the stream.

반환 값

A reference to the basic_ostream object.

설명

The <ostream> header also defines several global insertion operators. 자세한 내용은 operator<<(<ostream>)을 참조하십시오.

The first member function ensures that an expression of the form ostr << endl calls endl(ostr), and then returns *this. The second and third functions ensure that other manipulators, such as hex, behave similarly. The remaining functions are all formatted output functions.

The function

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

extracts elements from _Strbuf, if _Strbuf is not a null pointer, and inserts them. Extraction stops on end of file, or if an extraction throws an exception (which is rethrown). It also stops, without extracting the element in question, if an insertion fails. If the function inserts no elements, or if an extraction throws an exception, the function calls setstate(failbit). In any case, the function returns *this.

The function

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

converts _Val to a Boolean field and inserts it by calling use_facet<num_put<Elem, OutIt>(getloc). put(OutIt(rdbuf), *this, getloc, val). Here, OutIt is defined as ostreambuf_iterator<Elem, Tr>. The function returns *this.

The functions

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

each convert _Val to a numeric field and insert it by calling use_facet<num_put<Elem, OutIt>(getloc). put(OutIt(rdbuf), *this, getloc, val). Here, OutIt is defined as ostreambuf_iterator<Elem, Tr>. The function returns *this.

The functions

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

each convert _Val to a numeric field and insert it by calling use_facet<num_put<Elem, OutIt>(getloc). put(OutIt(rdbuf), *this, getloc, val). Here, OutIt is defined as ostreambuf_iterator<Elem, Tr>. The function returns *this.

예제

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

요구 사항

Header: <ostream>

네임스페이스: std

참고 항목

참조

basic_ostream 클래스

operator<<(<ostream>)

iostream 프로그래밍

iostreams 규칙