Skip to content

Latest commit

 

History

History
73 lines (59 loc) · 1.61 KB

tellp.md

File metadata and controls

73 lines (59 loc) · 1.61 KB

tellp

  • ostream[meta header]
  • std[meta namespace]
  • basic_ostream[meta class]
  • function[meta id-type]
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;
}
  • std::ostringstream[link ../../sstream/basic_ostringstream.md]
  • tellp[color ff0000]
  • str()[link ../../sstream/basic_ostringstream/str.md]
  • seekp[link seekp.md]

出力

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);
}
  • sentry[link sentry.md]
  • fail[link ../../ios/basic_ios/fail.md]
  • rdbuf[link ../../ios/basic_ios/rdbuf.md]
  • pubseekoff[link ../../streambuf/basic_streambuf/pubseekoff.md]

バージョン

言語

  • C++98

参照