std::basic_...ambuf::sgetc(3)
π NAME π
std::basic_streambuf::sgetc β ok so literally the whole name is just std::basic_streambuf::sgetc, bestie, that's the vibe. Also hi bestie, welcome to the C++ Standard Library corner of the manual, section 3, we're doing streambuf peek-y stuff today π«Ά
β¨ SYNOPSIS β¨
int_type sgetc();
Reads one character from the input sequence. Yes, just one. She's a one-character girlie and she's not sorry π
Here's the little plot twist you actually need to know: if the input sequence read position is not available, this bad girl returns underflow(). Otherwise? She returns Traits::to_int_type(*gptr()). No cap. That's the whole contract β¨
πΈ PARAMETERS πΈ
None. Nothing. Zero. Zilch. (none). The way she takes no arguments at all, iconic behaviour honestly π
π¦ RETURN VALUE π¦
The value of the character pointed to by the get pointer. That's it, that's the tea π
π EXAMPLE π
ok so peep this, it's giving peek() energy but make it streambuf:
// Run this code
#include <iostream>
#include <sstream>
int main()
{
std::stringstream stream("Hello, world");
std::cout << "sgetc() returned '" << (char)stream.rdbuf()->sgetc() << "'\n";
std::cout << "peek() returned '" << (char)stream.peek() << "'\n";
std::cout << "get() returned '" << (char)stream.get() << "'\n";
}
And the output, crown on:
sgetc() returned 'H'
peek() returned 'H'
get() returned 'H'
not all three of them returning 'H' π they all looked at her and none of them moved the cursor, she's literally still sitting there. main character energy fr fr π₯
π SEE ALSO π
sbumpcβ reads one character from the input sequence and advances the sequence (public member function). She actually moves. Unlike some people πstossc(removed in C++17) β advances the input sequence, then reads one character without advancing again (public member function). Girl got deleted from the standard, pour one out πsnextcβ advances the input sequence, then reads one character without advancing again (public member function)
ngl if you're mixing these up, just remember:sgetcpeeks,sbumpccommits,snextc/stosscdo the shuffle first. vibe check passed π
And that's the page, bestie! Big shoutout to http://cppreference.com, version 2024.06.10 β she's sourced, she's dated, she's citable, periodt πβ¨ Go read your streams and stay hydrated π§
π¦ 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