ostream::seekp
ostream& seekp ( streampos pos ); ostream& seekp ( streamoff off, ios_base::seekdir dir ); | ostream |
cplusplus.com |
Set position of the put pointer.
Sets the position of the put pointer. The put pointer determines the next location
where to write in the buffer associated to the output stream.
Parameters.
Return Value.
The function returns *this
Example.
// position of put pointer
#include <fstream>
using namespace std;
int main () {
long pos;
ofstream outfile;
outfile.open ("test.txt");
outfile.write ("This is an apple",16);
pos=outfile.tellp();
outfile.seekp (pos-7);
outfile.write (" sam",4);
outfile.close();
return 0;
}
In this example seekp is used to move the put pointer back to a position 7 characters
before the end of the first output operation. The final content of the file shall be:
This is a sample
Basic template member declaration ( basic_ostream<charT,traits> ):
typedef traits::pos_type pos_type; typedef traits::off_type off_type; basic_ostream& seekp ( pos_type pos ); basic_ostream& seekp ( off_type off, ios_base::seekdir dir ); |
See also.
tellp,
istream::seekg,
istream::tellg
ostream class