std::basic_...buf::seekpos(3)
okay so this is std::basic_...buf::seekpos(3), straight outta the C++ Standard Libary, and it's giving very niche, very protected, very virtual energy π
β¨
π NAME π
std::basic_stringbuf::seekpos - std::basic_stringbuf::seekpos β yes bestie, the name is literally the same twice, iconic π
β¨ SYNOPSIS β¨
protected:
virtual pos_type seekpos( pos_type sp,
std::ios_base::openmode which =
std::ios_base::in |
std::ios_base::out );
So what does it do? It repositions std::basic_streambuf::gptr and/or std::basic_streambuf::pptr, if possible, to the position indicated by sp.
It effectively executes seekoff(off_type(sp), std::ios_base::beg, which). no cap π«Ά
πΈ PARAMETERS πΈ
spβ stream position, such as one obtained byseekoff()orseekpos().whichβ defines whether the input sequences, the output sequence, or both are affected. It can be one or a combination of the following constants:inβ affect the input sequence.outβ affect the output sequence.
π«Ά RETURN VALUE π«Ά
sp on success or pos_type(off_type(-1)) on failure.
That's the whole vibe: success slays, failure gives negative-one energy ππ
π§ 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(). periodt π
π» 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.
π DEFECT REPORTS π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. history really said "we'll fix it later" and then did π
- LWG 375, applied to C++98 β static constant members of
std::ios_basewere misspecified as members ofstd::basic_ios; corrected. - LWG 564, applied to C++98 β it was unclear how to reposition
gptrand/orpptr; they are repositioned byseekoff().
π SEE ALSO π
pubseekposβ invokesseekpos()(public member function ofstd::basic_streambuf<CharT,Traits>).seekoff[virtual] β repositions the next pointer in the input sequence, output sequence, or both, using relative addressing (virtual protected member function).seekpos[virtual] β repositions the file position, using absolute addressing (virtual protected member function ofstd::basic_filebuf<CharT,Traits>).seekpos[virtual] β repositions the next pointer in the input sequence, output sequence, or both using absolute addressing (virtual protected member function ofstd::strstreambuf).
cute little sign-off bestie: this page came from http://cppreference.com, version 2024.06.10, and it's the std::basic_...buf::seekpos(3) manual page. bye and go reposition something ππ¦
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms