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

std::ostrstream::str

char* str();

?

?

冻结缓冲区后,返回指向缓冲区开头的指针。有效呼叫rdbuf()->str()...

注记

在打电话到str()如果将结果用作C字符串,则流缓冲区必须以空结尾.。常规输出,如stream << 1.2不存储空终止符,必须显式地追加它,通常与机械手一起使用。std::ends...

在打电话给str()动态的溪流冻结。打电话给freeze(false)在退出ostrstream对象被创建。否则,析构函数将泄漏内存。此外,当被冻结的流到达分配缓冲区的末尾时,可能会截断该流的附加输出,这可能会使缓冲区不以空终止。

参数

%280%29

返回值

中指向缓冲区开头的指针。std::strsteambufNULL如果没有可用的缓冲区。

二次

代码语言:javascript
复制
#include <strstream>
#include <iostream>
 
int main()
{
    std::ostrstream dyn; // dynamically-allocated output buffer
    dyn << "Test: " << 1.23; // not adding std::ends to demonstrate append behavior
    std::cout << "The output stream holds \"";
    std::cout.write(dyn.str(), dyn.pcount()) << "\"\n"; 
    // the stream is now frozen due to str()
    dyn << " More text" << std::ends;
    std::cout << "The output stream holds \"";
    std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
    dyn.freeze(false);
}

二次

可能的产出:

二次

代码语言:javascript
复制
The stream holds "Test: 1.23"
The stream holds "Test: 1.23 More "

二次

另见

str

marks the buffer frozen and returns the beginning pointer of the input sequence (public member function of std::strstreambuf)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com