Namespaces
Variants

operator<< (std::basic_ostream)

From cppreference.net
翻訳のポイント: - `rvalue` → `右辺値` (C++の専門用語としてそのまま翻訳) - `deleted overloads` → `削除されたオーバーロード` - `UTF character/array` → `UTF 文字/配列` - `(since C++11)` → `(C++11以降)` - HTMLタグ、属性、コード部分は完全に保持 - C++固有の用語は翻訳せず、技術文書としての正確性を維持 **翻訳結果:** **注記:** このコードはC++のテンプレート宣言と演算子オーバーロードの削除宣言を含んでおり、HTMLタグ内のコード部分は翻訳対象外です。C++のキーワード(template, class, char, wchar_t, deleteなど)と構文はそのまま保持されています。 このC++コードは既にHTMLタグ内に適切に配置されており、翻訳対象となる自然言語のテキストは含まれていません。すべてがC++のコードとキーワードで構成されているため、指示に従って翻訳は行わず、元のフォーマットを保持します。 HTMLタグ、属性、コード内のテキストは翻訳せず、元のフォーマットを保持しました。C++固有の用語も翻訳していません。 このC++コードはテンプレートクラス`Traits`に対する`basic_ostream `の`char16_t`型を出力する`operator<<`演算子が**削除済み**として宣言されていることを示しています。HTMLタグ、属性、コード内のC++キーワードや構文はすべて元のまま保持されています。 このC++コードは以下の内容を表しています: - `template `:Traitsクラスをテンプレートパラメータとするテンプレート宣言 - `basic_ostream &`:ワイド文字ストリームの出力ストリーム型 - `operator<<`:出力演算子のオーバーロード - `(basic_ostream & os, char32_t ch)`:パラメータとしてワイド文字ストリームとchar32_t文字を受け取る - `= delete;`:この演算子オーバーロードを明示的に削除(使用不可) C++の専門用語は翻訳せず、HTMLタグと属性もそのまま保持しています。 HTMLタグ、属性、C++コード内のテキストはすべて原文のまま保持されています。このC++コードはテンプレートクラス`Traits`を使用した`basic_ostream`の`operator<<`オーバーロードで、`const wchar_t*`型の引数を受け取るバージョンが`delete`指定されていることを示しています。 このC++コードは以下の内容を表しています: - `template `:Traitsクラスをテンプレートパラメータとするテンプレート宣言 - `basic_ostream &`:文字型charとTraitsを使用するbasic_ostreamへの参照 - `operator<<`:出力演算子のオーバーロード - `(basic_ostream & os, const char8_t* s)`:パラメータとしてbasic_ostream参照とchar8_tポインタを受け取る - `= delete;`:この演算子オーバーロードを明示的に削除(使用不可) このコードはchar8_t型の文字列をbasic_ostream に出力する演算子を削除していることを示しています。 **翻訳結果:** **翻訳の説明:** - `operator` → `演算子` - `delete` → `削除` - HTMLタグ、属性、C++コード内のキーワード(template, class, char, const, char16_tなど)は翻訳せず保持 - 書式設定と構造は完全に維持 HTMLタグ、属性、C++コードはすべて原文のまま保持されています。翻訳対象の自然言語テキストが含まれていないため、出力は入力と同一です。 HTMLタグ、属性、コード内のテキストは翻訳せず、元のフォーマットを保持しました。C++固有の用語も翻訳していません。 (注:指定されたHTML要素内には翻訳対象のテキストが含まれていないため、元の構造をそのまま保持しています)
ヘッダで定義 <ostream>
basic_ostream と文字
(1)
template < class CharT, class Traits >

basic_ostream < CharT, Traits > &

operator << ( basic_ostream < CharT, Traits > & os, CharT ch ) ;
template < class CharT, class Traits >

basic_ostream < CharT, Traits > &

operator << ( basic_ostream < CharT, Traits > & os, char ch ) ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, char ch ) ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, signed char ch ) ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, unsigned char ch ) ;
basic_ostreamと文字配列
(2)
template < class CharT, class Traits >

basic_ostream < CharT, Traits > &

operator << ( basic_ostream < CharT, Traits > & os, const CharT * s ) ;
template < class CharT, class Traits >

basic_ostream < CharT, Traits > &

operator << ( basic_ostream < CharT, Traits > & os, const char * s ) ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, const char * s ) ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, const signed char * s ) ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, const unsigned char * s ) ;
basic_ostream 右辺値
template < class Ostream, class T >
Ostream && operator << ( Ostream && os, const T & value ) ;
(3) (C++11以降)
basic_ostream および UTF 文字/配列に対する削除されたオーバーロード
(4) (C++20以降)
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, wchar_t ch ) = delete ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, wchar_t ch ) = delete ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, char8_t ch ) = delete ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, char16_t ch ) = delete ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, char32_t ch ) = delete ;
template < class Traits >

basic_ostream < wchar_t , Traits > &

operator << ( basic_ostream < wchar_t , Traits > & os, char8_t ch ) = delete ;
template < class Traits >

basic_ostream < wchar_t , Traits > &

operator << ( basic_ostream < wchar_t , Traits > & os, char16_t ch ) = delete ;
template < class Traits >

basic_ostream < wchar_t , Traits > &

operator << ( basic_ostream < wchar_t , Traits > & os, char32_t ch ) = delete ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, const wchar_t * s ) = delete ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, const char8_t * s ) = delete ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, const char16_t * s ) = delete ;
template < class Traits >

basic_ostream < char , Traits > &

演算子 << ( basic_ostream < char , Traits > & os, const char16_t * s ) = 削除 ;
template < class Traits >

basic_ostream < char , Traits > &

operator << ( basic_ostream < char , Traits > & os, const char32_t * s ) = delete ;
template < class Traits >

basic_ostream < wchar_t , Traits > &

operator << ( basic_ostream < wchar_t , Traits > & os, const char8_t * s ) = delete ;
template < class Traits >

basic_ostream < wchar_t , Traits > &

operator << ( basic_ostream < wchar_t , Traits > & os, const char16_t * s ) = delete ;
template < class Traits >

basic_ostream < wchar_t , Traits > &

演算子 << ( basic_ostream < wchar_t , Traits > & os, const char32_t * s ) = 削除済み ;

文字または文字列を挿入します。

1) FormattedOutputFunction として振る舞う。 sentry オブジェクトを構築・チェックした後、文字 ch を挿入する。 ch の型が char であり、かつ os character container type char でない場合、 os. widen ( ch ) が代わりに挿入される。
パディングは以下のように決定されます:
  • もし os. width ( ) > 1 の場合、 os. width ( ) - 1 個の os. fill ( ) のコピーが出力文字に追加され、出力文字シーケンスを形成します。
  • もし ( out. flags ( ) & std:: ios_base :: adjustfield ) == std:: ios_base :: left の場合、フィル文字は出力文字の後に配置され、それ以外の場合は前に配置されます。
挿入後、 os. width ( 0 ) が呼び出され、もしあれば std::setw の効果がキャンセルされます。
2) FormattedOutputFunction として振る舞う。セントリオブジェクトを構築・チェックした後、 s が指す先頭要素からの連続する文字を挿入する。
  • 第1および第3のオーバーロード( CharT ch の型と一致する場合)では、正確に traits :: length ( s ) 文字が挿入される。
  • 第2のオーバーロードでは、正確に std:: char_traits < char > :: length ( s ) 文字が挿入される。
  • 最後の2つのオーバーロードでは、正確に traits :: length ( reinterpret_cast < const char * > ( s ) ) 文字が挿入される。
挿入前に、まず全ての文字は os. widen ( ) を使用してワイド文字に変換され、その後パディングは以下のように決定されます:
  • 挿入する文字数が os. width ( ) より少ない場合、 os. fill ( ) のコピーを文字シーケンスに追加して、その長さを os. width ( ) と等しくします。
  • もし ( out. flags ( ) & std:: ios_base :: adjustfield ) == std:: ios_base :: left の場合、フィル文字は出力シーケンスの末尾に追加されます。それ以外の場合は出力シーケンスの前に追加されます。
挿入後、 os. width ( 0 ) が呼び出され、 std::setw の効果があればそれを取り消します。
s がヌルポインタの場合、動作は未定義です。
3) 出力ストリームオブジェクトへの右辺値参照に対して適切な挿入演算子を呼び出す( os << value と同等)。このオーバーロードは、 os << value という式が適切に形成され、かつ Ostream std::ios_base から公開かつ明確に派生したクラス型である場合にのみ、オーバーロード解決に参加する。
4) char16_t char32_t など(またはそれらのnull終端シーケンス)を受け入れるオーバーロードは削除されました: std:: cout << u 'X' は許可されません。以前はこれらは整数値またはポインタ値を出力していました。

目次

パラメータ

os - データを挿入する出力ストリーム
ch - 挿入する文字への参照
s - 挿入する文字列へのポインタ

戻り値

1,2) os
3) std :: move ( os )

注記

LWG issue 1203 以前は、 LWG issue 1203 より前では、以下のようなコード ( std:: ostringstream ( ) << 1.2 ) . str ( ) はコンパイルできませんでした。

#include <fstream>
#include <iostream>
void foo()
{
    // エラー: operator<< (basic_ostream<char, _Traits>&, char8_t) は削除されています
//  std::cout << u8'z' << '\n';
}
std::ostream& operator<<(std::ostream& os, char8_t const& ch)
{
    return os << static_cast<char>(ch);
}
int main()
{
    std::cout << "Hello, world" // `const char*` オーバーロードを使用
              << '\n';          // `char` オーバーロードを使用
    std::ofstream{"test.txt"} << 1.2; // rvalue オーバーロードを使用
    std::cout << u8'!' << '\n'; // プログラム定義の operator<<(os, char8_t const&) を使用
}

出力:

Hello, world
!

不具合報告

以下の動作変更に関する欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR 適用対象 公開時の動作 正しい動作
LWG 167 C++98 すべてのオーバーロードで挿入される文字数が
(2) において traits :: length ( s ) であった
CharT の型が ch の型と一致しないオーバーロードの
文字数を更新
LWG 1203 C++11 右辺値ストリームのオーバーロードが
基底クラスの左辺値参照を返した
派生クラスの右辺値参照を
返す
LWG 2011 C++98 パディングが std::num_put::do_put() によって決定された 演算子自体によって
決定される
LWG 2534 C++11 右辺値ストリームのオーバーロードが
制約されていなかった
制約されている

関連項目

書式化されたデータを挿入
(public member function)
引数の 書式化 された表現を出力
(function template)
文字をワイド文字に変換
(public member function of std::basic_ios<CharT,Traits> )