• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <ostream>

    std::basic_ostream::tellp

    pos_type tellp();
    

    概要

    ストリームバッファから現在の書き込み位置を取得する。

    戻り値

    備考

    C++11 から、本関数の処理開始時に sentry オブジェクトを構築するようになった。

    #include <iostream>
    #include <sstream>
    
    int main() {
      std::ostringstream os;
      os << "ABC";
      auto pos = os.tellp();
    
      os << "def";
      std::cout << os.str() << std::endl;
    
      os.seekp(pos);
      os << "DEF";
      std::cout << os.str() << std::endl;
    }
    

    出力

    ABCdef
    ABCDEF
    

    実装例

    pos_type tellp(pos_type pos) {
      sentry s(*this);
      if (this->fail()) {
        return pos_type(-1);
      }
      return this->rdbuf()->pubseekoff(0, cur, ios_base::out);
    }
    

    バージョン

    言語

    • C++98

    参照