Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::basic_ostream::seekp(3)  C++ Standard Libary std::basic_ostream::seekp(3)

NAME
       std::basic_ostream::seekp - std::basic_ostream::seekp

Synopsis
	  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 stream-
       buf object.

	  Behaves   as	 UnformattedOutputFunction  (except  without  actually
       (since C++11)
	  performing output). After constructing and checking the  sentry  ob-
       ject,

	  1) if	fail() != true,	sets the output	position indicator to absolute
       (relative to
	  the  beginning  of  the file)	value pos by calling rdbuf()->pubseek-
       pos(pos,
	  std::ios_base::out).	 In    case    of    failure,	 calls	  set-
       state(std::ios_base::failbit).
	  2)  if  fail() != true, sets the output position indicator to	offset
       off relative to
	  dir by calling rdbuf()->pubseekoff(off, dir, std::ios_base::out). In
       case of
	  failure, calls setstate(std::ios_base::failbit).

Parameters
	  pos -	absolute position to set the output position indicator to
	  off -	relative position (positive or negative) to set	the output po-
       sition indicator
		to
		defines	base position to apply the relative offset to. It  can
       be one of the
		following constants:

	  dir -	Constant Explanation
		beg	 the beginning of a stream
		end	 the ending of a stream
		cur	 the current position of stream	position indicator

Return value
	  *this

Exceptions
	  1,2)	May throw std::ios_base::failure in case of failure, if	excep-
       tions() & failbit
	  != 0.

Example
       // Run this code

	#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!

	  Defect reports

	  The following	behavior-changing defect reports were applied retroac-
       tively to
	  previously published C++ standards.

	     DR	   Applied to	      Behavior as published		  Cor-
       rect behavior
	  LWG  129   C++98	 there	was  no	way to indicate	a failure sets
       failbit on failure
	  LWG 136  C++98      seekp could set the input	stream	     only sets
       the output
								     stream
	  LWG 537  C++98      1. the type of pos was pos_type&	      1.  cor-
       rected to pos_type
			      2.  the  type of off was off_type&       2. cor-
       rected to off_type
	  LWG 2341 C++98      the resolution of	LWG issue 129 for    restored
			      overload (2) was removed

See also
	  tellp	returns	the output position indicator
		(public	member function)
	  tellg	returns	the input position indicator
		(public	member function	of std::basic_istream<CharT,Traits>)
	  seekg	sets the input position	indicator
		(public	member function	of std::basic_istream<CharT,Traits>)

http://cppreference.com		  2024.06.10	  std::basic_ostream::seekp(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::basic_ostream::seekp&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help