std::basic_ostream<CharT,Traits>::seekp

Sets the output position indicator of the current associated streambuf object.

# Declarations

basic_ostream& seekp( pos_type pos );
basic_ostream& seekp( off_type off, std::ios_base::seekdir dir );

# Parameters

# Return value

*this

# Example

#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';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 129C++98there was no way to indicate a failuresets failbit on failure
LWG 136C++98seekp could set the input streamonly sets the output stream
LWG 537C++981. the type of pos was pos_type&2. the type of off was off_type&1. corrected to pos_type2. corrected to off_type
LWG 2341C++98the resolution of LWG issue 129 for overload (2) was removedrestored

# See also