次の方法で共有


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
    stream_buf オブジェクトへのポインター。

  • _Val
    ストリームに書き込む要素。

戻り値

basic_ostream オブジェクトへの参照。

解説

<ostream> のヘッダーは、一部のグローバルの出力ストリーム演算子を定義します。 詳細については、「operator<< (<ostream>)」を参照してください。

一つ目のメンバー関数は、フォーム ostr << endl の式が endl(ostr)を呼び出す確認し、*thisを返します。 2 番目と 3 番目の関数は、他のマニピュレーターが、hexなど、同じように動作することを確認します。 残りの関数はすべて、書式付き出力関数です。

関数

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

_Strbuf が null ポインターの場合、Get _Strbufから要素を挿入します。 抽出は、ファイルの終端に抽出 (再スローされる) 例外スローすれば、または停止します。 また、対象要素の取得に挿入が失敗すると停止します。 関数が要素を挿入するか、抽象型が例外をスローすれば、関数呼び出し setstate (failbit)。 いずれの場合も、関数の戻り値 *this

関数

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

_Val をブール値フィールドに変換し、use_facet<num_put<Elem, OutIt>(getlocを呼び出して挿入します)。 配置 (OutIt (rdbuf)、 *thisgetlocval)。 ここでは、OutItostreambuf_iterator**<Elem, Tr>**として定義されます。 関数の戻り値 *this

関数

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

数値フィールドへの各変換 _Val は use_facet<num_put<Elem, OutIt> (getloc) を呼び出すことによってこれを挿入します。 put (OutIt (rdbuf)、*thisgetlocval)。 ここでは、OutIt は **ostreambuf_iterator<Elem, Tr>**として定義されます。 関数の戻り値 *this

関数

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

数値フィールドへの変換の各_Val は use_facet<num_put<Elem, OutIt> (getloc) . put (OutIt (rdbuf)、*thisgetlocval) を呼び出すことによってこれを挿入します。 ここでは、OutIt は **ostreambuf_iterator<Elem, Tr>**として定義されます。 関数の戻り値 *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;
}

出力

i is cout
21
15
text in streambuf

必要条件

ヘッダー: の <ostream>

名前空間: std

参照

関連項目

basic_ostream クラス

operator<< (<ostream>)

iostream プログラミング

iostreams の規則