共用方式為


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 列舉型別。

傳回值

在 basic_ostream 物件的參考。

備註

如果 失敗false,第 10% 成員函式呼叫 (Function Call) newpos = rdbuf陣列 pos_type 暫存物件的 newpos-> pubseekpos(_Pos),否則為。 如果 fail 為 false,第二個函式呼叫 newpos = rdbuf-> pubseekoff(_Off, _Way)。 不論是哪一種,因此,如果off_type()newpos == (off_type) (- 1) (定位作業失敗),然後函式呼叫 (Function Call) 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

請參閱

參考

basic_ostream Class

iostream 程式設計

iostreams 慣例