std::basic_ostream<CharT,Traits>::seekp
提供: cppreference.com
< cpp | io | basic ostream
basic_ostream& seekp( pos_type pos ); | (1) | |
basic_ostream& seekp( off_type off, std::ios_base::seekdir dir ); | (2) | |
現在紐付けられている streambuf
オブジェクトの出力位置指示子を設定します。
(実際に出力を行わないことを除いて) UnformattedOutputFunction として動作します。 sentry オブジェクトの構築および確認の後、 | (C++11以上) |
1)rdbuf()->pubseekpos(pos, std::ios_base::out) を呼ぶことによって、絶対 (ファイルの先頭からの相対) 位置
pos
に出力位置指示子を設定します。 呼び出しが (pos_type)-1 を返した場合は setstate(failbit) を実行します。2)rdbuf()->pubseekoff(off, dir, std::ios_base::out) を呼ぶことによって、
dir
からの相対オフセット off
に出力位置指示子を設定します。 エラーを報告しません。 | (C++14未満) |
呼び出しが (pos_type)-1 を返した場合は setstate(failbit) を実行します。 | (C++14以上) |
目次 |
[編集]引数
pos | - | 出力位置指示子を設定する絶対位置 | ||||||||
off | - | 出力位置指示子を設定する相対位置 | ||||||||
dir | - | 相対オフセットを適用するベースの位置を定義します。 以下の定数のいずれかを指定できます。
|
[編集]戻り値
*this。
[編集]例外
2)
rdbuf()->pubseekoff() が例外を投げない限り例外を投げません。 | (C++14未満) |
失敗した場合は exceptions()& failbit !=0 であれば std::ios_base::failure を投げるかもしれません。 | (C++14以上) |
[編集]例
Run this code
#include <sstream>#include <iostream> int main(){std::ostringstream os("hello, world"); os.seekp(7); os <<'W'; os.seekp(0, std::ios_base::end); os <<'!'; os.seekp(0); os <<'H';std::cout<< os.str()<<'\n';}
出力:
Hello, World!
[編集]関連項目
出力位置指示子を返します (パブリックメンバ関数) | |
入力位置指示子を返します ( std::basic_istream<CharT,Traits> のパブリックメンバ関数) | |
入力位置指示子を設定します ( std::basic_istream<CharT,Traits> のパブリックメンバ関数) |