basic_ostream::seekp
出力ストリームのリセットの位置。
basic_ostream<_Elem, _Tr>& seekp(
pos_type _Pos
);
basic_ostream<_Elem, _Tr>& seekp(
off_type _Off,
ios_base::seekdir _Way
);
パラメーター
_Pos
ストリームの位置。_Off
オフセット相対的な _Way。_Way
ios_base::seekdir の列挙型の 1 つが。
戻り値
basic_ostream のオブジェクトへの参照。
解説
fail が falseの場合、pos_type の一時的なオブジェクト newposの最初のメンバー関数の呼び出し newpos = rdbuf-> pubseekpos(_Pos)。fail が false の場合は 2 newpos = rdbuf-> 関数呼び出しpubseekoff (_Off、_Way)。いずれの場合も、() off_typenewpos == () off_type (- 1) (配置操作は失敗します)、および関数呼び出し istr.setstate (failbit)。関数は、両方 *this。
使用例
// basic_ostream_seekp.cpp
// compile with: /EHsc
#include <fstream>
#include <iostream>
int main()
{
using namespace std;
ofstream x("basic_ostream_seekp.txt");
streamoff i = x.tellp();
cout << i << endl;
x << "testing";
i = x.tellp();
cout << i << endl;
x.seekp(2); // Put char in third char position in file
x << " ";
x.seekp(2, ios::end); // Put char two after end of file
x << "z";
}
必要条件
ヘッダー: <ostream>
名前空間: std