pos_type tellp();
概要
ストリームバッファから現在の書き込み位置を取得する。
戻り値
fail() == false
であれば、rdbuf()->pubseekoff(0, cur, out)
。fail() == true
であれば、pos_type(-1)
。
備考
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