std::strstr...uf::overflow(3)
π NAME π
std::strstreambuf::overflow β std::strstreambuf::overflow (yes bestie, it's listed twice, and that's the whole NAME vibe π
). This page is titled std::strstr...uf::overflow(3) and lives under the C++ Standard Libary manual β spelling stays exactly as the header gave it, no cap β¨.
β¨ Synopsis β¨
protected: (deprecated in C++98)
virtual int_type overflow( int_type c = EOF ); (removed in C++26)
Okay so this one appends the character c to the put area of the buffer, reallocating if possible π«Ά. The way it goes down is:
- If
c == EOF, does nothing. - Otherwise, if the put area has a write position available (
pptr() < epptr()), stores the character as if by*pptr()++ = c. - Otherwise, if the stream buffer mode is not dynamic or the stream buffer is currently frozen, the function fails and returns
EOF. - Otherwise, the function reallocates (or initially allocates) a dynamic array large enough to hold the contents of the current dynamic array (if any) plus at least one additional write position. If a pointer to the allocating function
pallocwas used in the constructor, that function is called with(*palloc)(n)wherenis the number of bytes to allocate, otherwisenew char[n]is used. If a pointer to the deallocating functionpfreewas used in the constructor, that function is called with(*pfree)(p)to deallocate the previous array, if needed, otherwisedelete[] pis used. If allocation fails, the function fails and returnsEOF.
Heads up bestie: the synopsis literally tags this as deprecated in C++98 and removed in C++26. The timeline is timelining πβ³
πΈ Parameters πΈ
cβ the character to store in the put area.
π Return value π
If c == EOF, returns some value other than EOF. Otherwise, returns (unsigned char)(c) on success, EOF on failure π.
π¦ Example π¦
// Run this code
#include <iostream>
#include <strstream>
struct mybuf : std::strstreambuf
{
int_type overflow(int_type c)
{
std::cout << "Before overflow(): size of the put area is " << epptr()-pbase()
<< " with " << epptr()-pptr() << " write positions available\n";
int_type rc = std::strstreambuf::overflow(c);
std::cout << "After overflow(): size of the put area is " << epptr()-pbase()
<< " with " << epptr()-pptr() << " write positions available\n";
return rc;
}
};
int main()
{
mybuf sbuf; // read-write dynamic strstreambuf
std::iostream stream(&sbuf);
stream << "Sufficiently long string to overflow the initial allocation, at least "
<< " on some systems.";
}
π Possible output: π
Before overflow(): size of the put area is 16 with 0 write positions available
After overflow(): size of the put area is 32 with 15 write positions available
Before overflow(): size of the put area is 32 with 0 write positions available
After overflow(): size of the put area is 64 with 31 write positions available
Before overflow(): size of the put area is 64 with 0 write positions available
After overflow(): size of the put area is 128 with 63 write positions available
π See also π
overflowβ writes characters to the associated output sequence from the put area[virtual](virtual protected member function ofstd::basic_streambuf<CharT,Traits>)overflowβ appends a character to the output sequence[virtual](virtual protected member function ofstd::basic_stringbuf<CharT,Traits,Allocator>)overflowβ writes characters to the associated file from the put area[virtual](virtual protected member function ofstd::basic_filebuf<CharT,Traits>)sputcβ writes one character to the put area and advances the next pointer (public member function ofstd::basic_streambuf<CharT,Traits>)putβ inserts a character (public member function ofstd::basic_ostream<CharT,Traits>)
Source/version/date shoutout, because the footer said so: http://cppreference.com Β· 2024.06.10 Β· page std::strstr...uf::overflow(3) π«Άπβ¨
π¦ 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