ostream::tellp
streampos tellp ( ); | ostream |
cplusplus.com |
Get position of the put pointer.
Returns 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 an object of
type streampos
representing the current position of the put pointer.
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 tellp is used to get the position of the put pointer
after the write operation. The pointer is moved 7 characters before to modify the file at that position,
so 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; pos_type tellp (); |
See also.
seekp,
istream::tellg,
istream::seekg,
ostream class