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

std::strstreambuf::strstreambuf

explicit strstreambuf( std::streamsize alsize = 0 );

(1)

?

strstreambuf( void* (*palloc)(std::size_t), void (*pfree)(void*) );

(2)

?

strstreambuf( char* gnext, std::streamsize n, char* pbeg = 0 );

(3)

?

strstreambuf( signed char* gnext, std::streamsize n, signed char* pbeg = 0 );

(4)

?

strstreambuf( unsigned char* gnext, std::streamsize n, unsigned char* pbeg = 0 );

(5)

?

strstreambuf( const char* gnext, std::streamsize n );

(6)

?

strstreambuf( const signed char* gnext, std::streamsize n);

(7)

?

strstreambuf( const unsigned char* gnext, std::streamsize n );

(8)

?

1%29构造一个std::strstreambuf对象:通过调用std::streambuf,将缓冲区状态初始化为“动态”%28--缓冲区将根据需要分配%29,将分配的大小初始化为提供的alsize,将分配初始化为NULL%28将使用new[]delete[]%29

2%29构造一个std::strstreambuf对象:通过调用std::streambuf,将缓冲区状态初始化为“动态”%28缓冲区将根据需要分配%29,将分配的大小初始化为未指定的值,将分配函数初始化为palloc和解压函数pfree

3-5%29构造astd::strstreambuf按以下步骤初始化:

属性调用默认构造函数来初始化基类。std::streambuf

b%29将缓冲区状态初始化为“常量”%28缓冲区是用户提供的固定大小的缓冲区%29。

C%29确定用户提供的数组中的元素数如下:n大于零,n被使用了。如果n是零,std::strlen(gnext)执行以确定缓冲区大小。如果n是阴性的,INT_MAX被使用了。

D%29配置std::basic_streambuf指针如下:pbeg为空指针,调用setg(gnext, gnext, gnext + N).如果pbeg不是空指针,则执行setg(gnext, gnext, pbeg)setp(pbeg, pbeg+N),其中N是前面确定的数组中的元素数。

6-8%29strstreambuf((char*)gnext, n),除非“常量”位设置在缓冲区状态,否则不允许向此缓冲区输出位掩码%28。

参数

alsize

-

the initial size of the dynamically allocated buffer

palloc

-

pointer to user-provided allocation function

pfree

-

pointer to user-provided deallocation function

gnext

-

pointer to the start of the get area in the user-provided array

pbeg

-

pointer to the start of the put area in the user-provided array

n

-

the number of bytes in the get area (if pbeg is null) or in the put area (if pbeg is not null) of the user-provided array

注记

的构造函数通常调用这些构造函数。std::strstream...

二次

代码语言:javascript
复制
#include <strstream>
#include <iostream>
 
int main()
{
    std::strstreambuf dyn; // dynamic
    std::strstream dyn_s; // equivalent stream
    dyn_s << 1.23 << std::ends;
    std::cout << dyn_s.str() << '\n';
    dyn_s.freeze(false);
 
    char buf[10];
    std::strstreambuf user(buf, 10, buf); // user-provided output buffer
    std::ostrstream user_s(buf, 10); // equivalent stream
    user_s << 1.23 << std::ends;
    std::cout << buf << '\n';
 
    std::strstreambuf lit("1 2 3", 5); // constant
    std::istrstream lit_s("1 2 3"); // equivalent stream
    int i, j, k;
    lit_s >> i >> j >> k;
    std::cout << i << ' ' << j << ' ' << k << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
1.23
1.23
1 2 3

二次

另见

(constructor)

constructs an strstream, optionally allocating the buffer (public member function of std::strstream)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com