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

std::basic_stringbuf::basic_stringbuf

explicit basic_stringbuf( std::ios_base::openmode which = std::ios_base::in | std::ios_base::out );

(1)

?

explicit basic_stringbuf( const std::basic_string<CharT, traits, Allocator>& new_str, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out );

(2)

?

basic_stringbuf( const basic_stringbuf& rhs ) = delete;

(3)

(since C++11)

basic_stringbuf( basic_stringbuf&& rhs );

(4)

(since C++11)

1%29构造一个std::basic_stringbuf对象:通过调用std::basic_streambuf,使用空字符串初始化字符序列,并将模式设置为which...

2%29构造一个std::basic_stringbuf对象,方法是执行与1%29相同的初始化,然后初始化关联的字符序列,就像调用str(new_str)...

3%29复制构造函数被删除;std::basic_stringbuf不是CopyConstructible

4%29移动-构造一个std::basic_stringbuf通过将所有状态从另一个状态移出来创建std::basic_stringbuf对象rhs,包括关联的字符串、打开模式、区域设置和所有其他状态。在移动之后,std::basic_streambuf*this中的相应指针-rhs除非是零。

参数

new_str

-

a basic_string used to initialize the buffer

rhs

-

another basic_stringbuf

mode

-

specifies stream open mode. It is bitmask type, the following constants are defined: Constant Explanation app seek to the end of stream before each write binary open in binary mode in open for reading out open for writing trunc discard the contents of the stream when opening ate seek to the end of stream immediately after open

Constant

Explanation

app

seek to the end of stream before each write

binary

open in binary mode

in

open for reading

out

open for writing

trunc

discard the contents of the stream when opening

ate

seek to the end of stream immediately after open

Constant

Explanation

app

seek to the end of stream before each write

binary

open in binary mode

in

open for reading

out

open for writing

trunc

discard the contents of the stream when opening

ate

seek to the end of stream immediately after open

注记

的构造函数通常调用std::basic_stringstream...

以外的开放模式的支持级别。std::ios_base::instd::ios_base::out实现各不相同。C++11显式指定对std::ios_base::atestr()在这个构造函数中,但是std::ios_base::app,,,std::ios_base::trunc,和std::ios_base::binary对不同的实现有不同的影响。

演示如何调用Basic的构造函数。[医]直接的弦乐。

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
 
int main()
{
    // default constructor (mode = in|out)
    std::stringbuf buf1;
    buf1.sputc('1');
    std::cout << &buf1 << '\n';
 
    // string constructor in at-end mode (C++11)
    std::stringbuf buf2("test", std::ios_base::in
                              | std::ios_base::out
                              | std::ios_base::ate);
    buf2.sputc('1');
    std::cout << &buf2 << '\n';
 
    // append mode test (results differ among compilers)
    std::stringbuf buf3("test", std::ios_base::in
                              | std::ios_base::out
                              | std::ios_base::app);
    buf3.sputc('1');
    buf3.pubseekpos(1);
    buf3.sputc('2');
    std::cout << &buf3 << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
1
test1
est12 (Sun Studio) 2st1 (GCC)

二次

另见

(constructor)

constructs the string stream (public member function of std::basic_stringstream)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com