basic_ostream::seekp
Reset position in output stream.
basic_ostream<_Elem, _Tr>& seekp(
pos_type _Pos
);
basic_ostream<_Elem, _Tr>& seekp(
off_type _Off,
ios_base::seekdir _Way
);
Parameters
_Pos
The position in the stream._Off
The offset relative to _Way._Way
One of the ios_base::seekdir enumerations.
Return Value
A reference to the basic_ostream object.
Remarks
If fail is false, the first member function calls newpos = rdbuf-> pubseekpos(_Pos), for some pos_type temporary object newpos. If fail is false, the second function calls newpos = rdbuf-> pubseekoff(_Off, _Way). In either case, if (off_type)newpos == (off_type)(-1) (the positioning operation fails), then the function calls istr.setstate(failbit). Both functions return *this.
Example
// 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";
}
0 7
Requirements
Header: <ostream>
Namespace: std