| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Global objects | ||||
| Member functions | ||||
(C++11) | ||||
| Formatted output | ||||
| Unformatted output | ||||
| Positioning | ||||
basic_ostream::seekp | ||||
| Miscellaneous | ||||
(C++11) | ||||
| Member classes | ||||
| Non-member functions | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
basic_ostream& seekp( pos_type pos); | (1) | |
basic_ostream& seekp( off_type off,std::ios_base::seekdir dir); | (2) | |
Sets the output position indicator of the current associatedstreambuf object.
Behaves asUnformattedOutputFunction (except without actually performing output). After constructing and checking the sentry object, | (since C++11) |
Contents |
| pos | - | absolute position to set the output position indicator to | ||||||||
| off | - | relative position (positive or negative) to set the output position indicator to | ||||||||
| dir | - | defines base position to apply the relative offset to. It can be one of the following constants:
|
*this
#include <iostream>#include <sstream> int main(){std::ostringstream os("hello, world"); os.seekp(7); os<<'W'; os.seekp(0,std::ios_base::end); os<<'!'; os.seekp(0); os<<'H';std::cout<< os.str()<<'\n';}
Output:
Hello, World!
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 129 | C++98 | there was no way to indicate a failure | setsfailbit on failure |
| LWG 136 | C++98 | seekp could set the input stream | only sets the output stream |
| LWG 537 | C++98 | 1. the type ofpos waspos_type&2. the type ofoff was off_type& | 1. corrected topos_type2. corrected to off_type |
| LWG 2341 | C++98 | the resolution ofLWG issue 129 for overload (2) was removed | restored |
| returns the output position indicator (public member function)[edit] | |
| returns the input position indicator (public member function of std::basic_istream<CharT,Traits>)[edit] | |
| sets the input position indicator (public member function of std::basic_istream<CharT,Traits>)[edit] |