std::basic_stringbuf<CharT,Traits,Allocator>::seekpos
From cppreference.com
 
 
 < cpp | io | basic stringbuf 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Input/output library 
 
 
 
 
 
 
 
 
 
 
 
 
 Print functions (C++23)
 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)
std::basic_stringbuf 
 
 
 
 
 
 
 Public member functions
(C++11)
(C++11)
(C++20)
(C++20)
 Protected member functions
basic_stringbuf::seekpos
 Non-member functions
(C++11)
 Exposition-only member functions
protected:
 
 
virtual pos_type seekpos( pos_type sp,
Repositions std::basic_streambuf::gptr and/or std::basic_streambuf::pptr , if possible, to the position indicated by sp.
Effectively executes seekoff(off_type(sp), std::ios_base::beg, which).
[edit] Parameters
 sp
 -
 stream position, such as one obtained by seekoff()  or 
seekpos()
 which
 -
 defines whether the input sequences, the output sequence, or both are affected. It can be one or a combination of the following constants:
 
 
 repositions the next pointer in the input sequence, output sequence, or both, using relative addressing 
(virtual protected member function) [edit]
 
 repositions the file position, using absolute addressing 
(virtual protected member function of
 
 
 
 
 
 
 
 
 
  Constant
 Explanation
 in
 affect the input sequence
 out
 affect the output sequence
[edit] Return value
sp on success or pos_type(off_type(-1)) on failure.
[edit] 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() .
[edit] Example
Run this code
#include <sstream> #include <iostream> struct mybuf : std::stringbuf { mybuf(const std::string & str) : std::stringbuf (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 available.\n"; pos_type rc = std::stringbuf::seekpos(sp, which); std::cout << "seekpos() returns " << rc << ".\nAfter the call, " << "size of the get area is " << egptr() - eback() << " with " << egptr() - gptr() << " read positions available.\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 available.
[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 375 | C++98 | static constant members of std::ios_base  were misspecified as members of std::basic_ios | corrected | 
| LWG 564 | C++98 | if was unclear how to reposition gptrand/orpptr | they are repositioned by seekoff() | 
[edit] See also
[virtual]
(virtual protected member function) [edit]
[virtual]
(virtual protected member function of
std::basic_filebuf<CharT,Traits>) [edit]