首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::strstreambuf::overflow

protected: virtual int_type overflow (int_type c = EOF);

?

?

附加字符c到缓冲区的PUT区域,如果可能的话重新分配。

1%29c==EOF,什么都不做

2%29否则,如果PUT区域有可用的写入位置,则为%28pptr() < epptr()%29,将字符存储为*pptr()++ = c

3%29否则,如果流缓冲区模式不是动态的,或者流缓冲区当前已被冻结,则该函数将失败并返回。EOF

4%29否则,函数重新分配%28或最初分配%29一个足够大的动态数组,如果有任何%29,再加上至少一个额外的写入位置,该动态数组足够容纳当前动态数组%28的内容。如果指向分配器函数的指针palloc在构造函数中使用,则该函数将在(*palloc)[n]何地n为要分配的字节数,则为new char[n]被使用了。如果指向释放函数的指针pfree在构造函数中使用,则该函数将在(*pfree)(p)若要释放前一个数组,如果需要,则为delete[] p被使用了。如果分配失败,则函数将失败并返回EOF...

参数

c

-

the character to store in the put area

返回值

如果c==EOF,返回其他值。EOF.否则,返回(unsigned char)(c)在成功的时候,EOF在失败的时候。

二次

代码语言:javascript
复制
#include <strstream>
#include <iostream>
 
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.";
}

二次

可能的产出:

二次

代码语言:javascript
复制
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

二次

另见

overflow virtual

writes characters to the associated output sequence from the put area (virtual protected member function of std::basic_streambuf)

overflow virtual

appends a character to the output sequence (virtual protected member function of std::basic_stringbuf)

overflow virtual

writes characters to the associated file from the put area (virtual protected member function of std::basic_filebuf)

sputc

writes one character to the put area and advances the next pointer (public member function of std::basic_streambuf)

put

inserts a character (public member function of std::basic_ostream)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com