std::basic_ostream<CharT,Traits>::seekp
| 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 associated streambuf object.
|
Behaves as UnformattedOutputFunction (except without actually performing output). After constructing and checking the sentry object, |
(since C++11) |
pos by calling rdbuf()->pubseekpos(pos, std::ios_base::out). If the call returns (pos_type)-1, executes setstate(failbit).off relative to dir by calling rdbuf()->pubseekoff(off, dir, std::ios_base::out). If the call returns (pos_type)-1, executes setstate(failbit).Contents |
[edit] Parameters
| 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:
|
[edit] Return value
*this
[edit] Exceptions
[edit] Example
#include <sstream> #include <iostream> 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!
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2341 | C++98 | two overloads behaved differently on failure | made consistent |
[edit] See also
| returns the output position indicator (public member function) | |
| returns the input position indicator (public member function of std::basic_istream<CharT,Traits>)
| |
| sets the input position indicator (public member function of std::basic_istream<CharT,Traits>)
|

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
