std::ios_base::seekdir(3)
π NAME π
std::ios_base::seekdir - std::ios_base::seekdir
Okay bestie, welcome to the std::ios_base::seekdir(3) page from the C++ Standard Libary manual β yes, that spelling is straight from the header, don't come for me ππ
This is the seek-direction type page, so if you've ever needed to tell a stream "bestie, go back to the start" or "wait, stay right there," this is your moment β¨
β¨ Synopsis β¨
typedef /*implementation defined*/ seekdir;
static constexpr seekdir beg = /*implementation defined*/
static constexpr seekdir end = /*implementation defined*/
static constexpr seekdir cur = /*implementation defined*/
It specifies the file seeking direction type. The following constants are defined:
begβ the beginning of a stream π±endβ the ending of a stream πcurβ the current position of stream position indicator π
π Example π
// Run this code
#include <iostream>
#include <sstream>
#include <string>
int main()
{
std::istringstream in("Hello, World!");
std::string word1, word2, word3, word4, word5;
in >> word1;
in.seekg(0, std::ios_base::beg); // <- rewind
in >> word2;
in.seekg(1, std::ios_base::cur); // -> seek from cur pos toward the
end
in >> word3;
in.seekg(-6, std::ios_base::cur); // <- seek from cur pos (end)
toward begin
in >> word4;
in.seekg(-6, std::ios_base::end); // <- seek from end toward begin
in >> word5;
std::cout << "word1 = " << word1 << '\n'
<< "word2 = " << word2 << '\n'
<< "word3 = " << word3 << '\n'
<< "word4 = " << word4 << '\n'
<< "word5 = " << word5 << '\n';
}
π Output: π
word1 = Hello,
word2 = Hello,
word3 = World!
word4 = World!
word5 = World!
π See also π
seekgβ sets the input position indicator (public member function ofstd::basic_istream<CharT,Traits>) πseekpβ sets the output position indicator (public member function ofstd::basic_ostream<CharT,Traits>) πpubseekoffβ invokesseekoff()(public member function ofstd::basic_streambuf<CharT,Traits>) π
That's the whole page, bestie! Source: http://cppreference.com πΈ Date/version: 2024.06.10 π May your seeks always land exactly where you meant, no cap β¨π
π¦ 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