In C++, seekp() moves the put position, the place where the next write goes, in an output stream. The letter p stands for put.
With it you can go back and overwrite text that was written earlier, for example to fix a placeholder in a file. It works on file streams and string streams. Include <iostream> to use it.
This is a member function of std::ostream. You call it with a dot on a stream object, for example std::cin, std::cout, a file stream, or a std::stringstream. A stream is simply C++'s way to read or write data one piece after another.
Syntax
Give a position, or an offset together with a starting point.
C++
out.seekp(6); // 6 characters from the start
out.seekp(0, std::ios::end); // to the end
out.seekp(-2, std::ios::cur); // 2 characters back
Call
What it does
out.seekp(6)
The next write goes to position 6.
out.seekp(0, std::ios::end)
The next write goes to the end.
out.seekp(-2, std::ios::cur)
Moves two characters back from the current place.
Writing at a position replaces the characters that were there. It does not push the rest of the text aside.