mardi 17 août 2021

Using pubseekoff() instead of seekg() and seekp() to seek to another position

I'm writing a wrapper over std::fstream and stuck a bit with seekp() and seekg() functions.

All I need here is a uniform seek function which behaves mostly as lseek() - repositions the file offset of the open file (here the position indicator associated with the stream) to a new position, independently is it open for read, write or both.

Although underneath seekp() and seekg() refers to the same pointer and could be used interchangeable but I suppose it is not good to use seekp with RO mode and vise versa.

According to man both seekp() and seekg() call std::streambuf::pubseekoff() function.

Is it ok to call it directly, e.g.

file_streab_obj.rdbuf()->pubseekoff(off, way)

If no, please explain why and guide me to the better solution if possible.

Aucun commentaire:

Enregistrer un commentaire