- ostream[meta header]
- std[meta namespace]
- basic_ostream[meta class]
- function[meta id-type]
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;
}- 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