std::basic_istream::tellg(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 std::basic_istream::tellg 🌸

okay so this is the page for std::basic_istream::tellg, straight outta the C++ Standard Libary manual (yes, that spelling, periodt πŸ’…). It’s basically your input stream’s β€œwhere are we rn?” button, and honestly? iconic. 🫢

✨ NAME ✨

std::basic_istream::tellg β€” that’s the whole name, bestie, no cap. This is the C++ Standard Libary manual page for it, and it’s giving β€œget-pointer gossip reporter” energy. πŸ’–

πŸ¦‹ Synopsis πŸ¦‹

pos_type tellg();

So here’s the vibe: tellg() returns the input position indicator of the current associated streambuf object. It behaves as an UnformattedInputFunction, except that gcount() is not affected. After constructing and checking the sentry object, if fail() == true, it returns pos_type(-1). Otherwise, it returns rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::in). Slay. πŸ’…

πŸŽ€ Parameters πŸŽ€

  • none β€” literally zero parameters, bestie. Zilch. Nada. πŸ™ˆ

πŸ’– Return value πŸ’–

  • On success: the current position of the get pointer ✨
  • On failure: pos_type(-1) πŸ’€

πŸ”₯ Exceptions πŸ”₯

  • Throws failure if an error occurred (the error state flag is not goodbit) and exceptions() is set to throw for that state. 😭
  • If an internal operation throws an exception, it is caught and badbit is set. If exceptions() is set for badbit, the exception is rethrown. 🚨

🌈 Example 🌈

Run this code, bestie:

#include <iostream>
#include <sstream>
#include <string>

int main()
{
    std::string str = "Hello, world";
    std::istringstream in(str);
    std::string word;
    in >> word;
    std::cout << "After reading the word \"" << word
              << "\" tellg() returns " << in.tellg() << '\n';
}

πŸ“ Output πŸ“

After reading the word "Hello," tellg() returns 6

πŸ‘‘ See also πŸ‘‘

  • seekoff β€” repositions the file position, using relative addressing [virtual] (virtual protected member function of std::basic_filebuf<CharT,Traits>)
  • seekoff β€” repositions the next pointer in the input sequence, output sequence, or both, using relative addressing [virtual] (virtual protected member function of std::basic_stringbuf<CharT,Traits,Allocator>)
  • seekoff β€” repositions the next pointer in the input sequence, output sequence, or both, using relative addressing [virtual] (virtual protected member function of std::strstreambuf)
  • seekg β€” sets the input position indicator (public member function)
  • tellp β€” returns the output position indicator (public member function of std::basic_ostream<CharT,Traits>)
  • seekp β€” sets the output position indicator (public member function of std::basic_ostream<CharT,Traits>)

okay that’s the whole page, bestie 🫢 β€” source/version: http://cppreference.com β€’ date: 2024.06.10. Catch u later, mwah πŸ’‹

πŸ“¦ where this page comes from