GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::operator<< - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. string
  3. basic_string
  4. operator<<

最終更新日時: 2026年08月26日 11時09分20秒 (JST)
Akira Takahashi が更新

履歴 編集

function template
<string>

std::operator<<

namespace std {
  template<class CharT, class Traits, class Allocator>
  std::basic_ostream<CharT, Traits>&
    operator<<(std::basic_ostream<CharT, Traits>& os,
               const basic_string<CharT, Traits, Allocator>& s);
}

概要

文字列をストリームへ出力する。

効果

書式化出力関数として振る舞う。

  1. sentryオブジェクトを構築する。sentryオブジェクトが失敗を示した場合、何もしない。
  2. 出力する文字列を決定する。初期状態はイテレータ範囲[s.begin(), s.end())の要素からなる文字列である。
    • s.size()がos.width()より小さい場合、os.width()文字の幅になるまで、必要な数のos.fill()をこの文字列へ追加する。
    • (os.flags() &std::ios_base::adjustfield) ==std::ios_base::leftである場合、埋め文字は文字列の後ろに置かれる。そうでない場合は前に置かれる。
  3. 上記で得られた文字列seqを、os.rdbuf()->sputn(seq, n)を呼び出したかのようにして出力する。ここでnはos.width()とs.size()のうち大きい方である。
  4. os.width(0)を呼び出す。

戻り値

os

例

#include <iostream>
#include <string>

int main() {
  std::string s = "Tuna";
  std::cout << s << std::endl;
}

出力例

Tuna

実装例

TBD

バージョン

言語

  • C++98

参照

  • このほかの<<演算子関数
    • <ostream>ヘッダで定義されているもの
  • LWG Issue 2011. Unexpected output required of strings
    • C++14で、パディングの決定方法がこの関数自身の規定として明記された
    • この修正は欠陥報告(DR)であり、C++98以降に遡及して適用される。元の規定は数値出力のためのnum_put::do_putの「Fill padding」表を参照していたため、std::ios_base::internal指定時に"0X1Y2Z"が"0X**1Y2Z"と出力されることを要求していたが、処理系は当初から"**0X1Y2Z"を出力していたため
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.