Cpp-standard-library-cpp-ostream-seekp

提供:Dev Guides
移動先:案内検索

C ++ Ostreamライブラリ-seekp

説明

出力シーケンスの位置を設定するために使用されます。

宣言

以下は、std
ostream :: seekpの宣言です。
(1) ostream& seekp (streampos pos);
(2) ostream& seekp (streamoff off, ios_base::seekdir way);

パラメーター

  • pos -ストリーム内の絶対位置を見つけるために使用されます。
  • off -wayパラメータに関連するオフセット値。

戻り値

ostreamオブジェクト(* this)を返します。

例外

基本保証-例外がスローされた場合、オブジェクトは有効な状態です。

データの競合

ストリームオブジェクトを変更すると、同じストリームオブジェクトへの同時アクセスがデータ競合を引き起こす可能性があります。

以下の例では、std
ostream :: seekpについて説明しています。
#include <fstream>

int main () {

   std::ofstream outfile;
   outfile.open ("finddevguides.txt");

   outfile.write ("This is an apple",16);
   long pos = outfile.tellp();
   outfile.seekp (pos-7);
   outfile.write (" sai",4);

   outfile.close();

   return 0;
}