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

FreeBSD Manual Pages

  
 
  

home | help
std::strstreambuf::seekpos(3) C++ Standard Libarystd::strstreambuf::seekpos(3)

NAME
       std::strstreambuf::seekpos - std::strstreambuf::seekpos

Synopsis
	  protected:

	  virtual pos_type seekpos( pos_type sp,			 (dep-
       recated in C++98)
				    std::ios_base::openmode  which =	  (re-
       moved in	C++26)

					std::ios_base::in |
	  std::ios_base::out );

	  Repositions  std::basic_streambuf::gptr  and/or   std::basic_stream-
       buf::pptr, if
	  possible, to the position indicated by sp.

	  If  std::ios_base::in	is set in which, attempts to reposition	gptr()
       (the next
	  pointer in the get area). If std::ios_base::out is set in which, at-
       tempts to
	  reposition pptr() (the next pointer in the put area).	If neither bit
       is set in
	  which, the operation fails.

	  Each next pointer is repositioned as follows:

	    * If the next pointer is null, the operation fails.
	    * Otherwise, the new offset	newoff (of type	 off_type)  is	deter-
       mined by	calling
	      sp.offset(). If newoff is	negative, out of bounds	of the buffer,
       or invalid, the
	      operation	fails.
	    *  Otherwise,  the	next  pointer  is  assigned  as	if by gptr() =
       eback() + newoff	or
	      pptr() = pbase() + newoff.

Parameters
	  sp	- stream position, such	as one obtained	by seekoff() or	 seek-
       pos()
		  defines whether the input sequences, the output sequence, or
       both are
		  affected.  It	 can  be one or	a combination of the following
       constants:
	  which	-
		  Constant Explanation
		  in	   affect the input sequence
		  out	   affect the output sequence

Return value
	  The  resultant  offset  converted  to	  pos_type   on	  success   or
       pos_type(off_type(-1)) on
	  failure.

Notes
	  seekpos()  is	called by std::basic_streambuf::pubseekpos(), which is
       called by the
	  single-argument versions of std::basic_istream::seekg() and
	  std::basic_ostream::seekp().

Example
       // Run this code

	#include <cstring>
	#include <iostream>
	#include <strstream>

	struct mybuf : std::strstreambuf
	{
	    mybuf(const	char* str) : std::strstreambuf(str,  std::strlen(str))
       {}

	    pos_type seekpos(pos_type sp, std::ios_base::openmode which)
	    {
		std::cout  <<  "Before	seekpos(" << sp	<< "), size of the get
       area is "
			  << egptr() - eback() << " with "
			  << egptr() -	gptr()	<<  "  read  positions	avail-
       able.\n";

		pos_type rc = std::strstreambuf::seekpos(sp, which);

		std::cout << "seekpos()	returns	" << rc	<< ".\nAfter the call,
       "
			  << "size of the get area is "
			  << egptr() - eback() << " with "
			  <<  egptr()  -  gptr()  <<  "	 read positions	avail-
       able.\n";

		return rc;
	    }
	};

	int main()
	{
	    mybuf buf("12345");
	    std::iostream stream(&buf);
	    stream.seekg(2);
	}

Output:
	Before seekpos(2), size	of the get area	is 5  with  5  read  positions
       available.
	seekpos() returns 2.
	After the call,	size of	the get	area is	5 with 3 read positions	avail-
       able.

	  Defect reports

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

	    DR	  Applied to	   Behavior as published	   Correct be-
       havior
	  LWG	 55    C++98	     seekpos	 returned     an     undefined
       pos_type(off_type(-1))
			    invalid  stream position on	failure	is returned on
       failure

See also
	  seekoff   repositions	the next pointer in the	input sequence,	output
       sequence, or
	  [virtual] both, using	relative addressing
		    (virtual protected member function)
		    repositions	the next pointer in the	input sequence,	output
       sequence, or
	  seekpos   both using absolute	addressing
	  [virtual] (virtual protected member function	of  std::basic_stream-
       buf<CharT,Traits>)

		    repositions	the next pointer in the	input sequence,	output
       sequence, or
	  seekpos   both using absolute	addressing
	  [virtual] (virtual protected member function of
		    std::basic_stringbuf<CharT,Traits,Allocator>)
	  seekpos   repositions	the file position, using absolute addressing
	  [virtual]  (virtual  protected  member  function of std::basic_file-
       buf<CharT,Traits>)

http://cppreference.com		  2024.06.10	 std::strstreambuf::seekpos(3)

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

home | help