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

std::strstream::freeze

void freeze(bool flag = true);

?

?

如果流使用动态分配的数组进行输出,则禁用%28。flag == true%29或启用%28flag == false%29缓冲区的自动分配/取消分配。有效呼叫rdbuf()->freeze(flag)...

注记

在打电话给str()动态流自动冻结。打电话给freeze(false)在退出strstream对象被创建。否则,析构函数将泄漏内存。另外,当被冻结的流到达分配缓冲区的末尾时,可能会截断它的额外输出。

参数

flag

-

desired status

返回值

%280%29

二次

代码语言:javascript
复制
#include <strstream>
#include <iostream>
 
int main()
{
    std::strstream dyn; // dynamically-allocated output buffer
    dyn << "Test: " << 1.23; // note: no std::ends to demonstrate appending
    std::cout << "The output stream contains \"";
    std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
    // the stream is now frozen due to str()
    dyn << " More text"; // output to a frozen stream may be truncated
    std::cout << "The output stream contains \"";
    std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
    dyn.freeze(false); // freeze(false) must be called or the  destructor will leak
 
    std::strstream dyn2; // dynamically-allocated output buffer
    dyn2 << "Test: " << 1.23; // note: no std::ends
    std::cout << "The output stream contains \"";
    std::cout.write(dyn2.str(), dyn2.pcount()) << "\"\n";
    dyn2.freeze(false);   // unfreeze the stream after str()
    dyn2 << " More text" << std::ends; // output will not be truncated (buffer grows)
    std::cout << "The output stream contains \"" << dyn2.str() << "\"\n";
    dyn2.freeze(false); // freeze(false) must be called or the  destructor will leak 
}

二次

可能的产出:

二次

代码语言:javascript
复制
The output stream contains "Test: 1.23"
The output stream contains "Test: 1.23 More "
The output stream contains "Test: 1.23"
The output stream contains "Test: 1.23 More text"

二次

另见

freeze

sets/clears the frozen state of the buffer (public member function of std::strstreambuf)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com