[ Web Proxy ]
URL:
Viewing: http://ru.cppreference.com/cpp/io/basic_stringbuf/basic_stringbuf [Back]  [Original]

std::basic_stringbuf::basic_stringbuf cppreference.com
cppreference.com

std::basic_stringbuf::basic_stringbuf

cppreference.com

<metanoindex/>

<tbody> </tbody>
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)
basic_stringbuf(basic_stringbuf&& rhs);
(4) ( C++11)
1)
std::basic_stringbuf : , std::basic_streambuf, , which.
:
Constructs a std::basic_stringbuf object: initializes the base class by calling the default constructor of std::basic_streambuf, initializes the character sequence with an empty string, and sets the mode to which.
Google.
. .
2)
std::basic_stringbuf , , 1),
(new_str)
:
str(new_str)
[http://translate.google.com Google].
. [http://en.cppreference.com/w/Cppreference:MachineTranslations ].
.
:
Constructs a std::basic_stringbuf object by performing the same initialization as 1), followed by initializing the associated character sequence as if by calling
(new_str)
:
str(new_str)
[http://translate.google.com Google].
. [http://en.cppreference.com/w/Cppreference:MachineTranslations ].
.
Google.
. .
3)
; std::basic_stringbuf CopyConstructible
:
The copy constructor is deleted; std::basic_stringbuf is not CopyConstructible
Google.
. .
4)
Move- std::basic_stringbuf , std::basic_stringbuf rhs, , , , . , std::basic_streambuf *this -rhs .
:
Move-constructs a std::basic_stringbuf object by moving all state from another std::basic_stringbuf object rhs, including the associated string, the open mode, the locale, and all other state. After the move, the six pointers of std::basic_streambuf in *this are guaranteed to be different from the corresponding pointers in the moved-from rhs unless null.
Google.
. .

new_str
basic_string
:
a basic_string used to initialize the buffer
Google.
. .
rhs
basic_stringbuf
:
another basic_stringbuf
Google.
. .
mode
. , :
app
binary
in
out
trunc
ate
noreplace (C++23)
:
specifies stream open mode. It is bitmask type, the following constants are defined:
app
binary
in
out
trunc
ate
noreplace (C++23)
Google.
. .

std::basic_stringstream.
:
Typically called by the constructor of std::basic_stringstream.
Google.
. .
, std::ios_base::in std::ios_base::out . C + +11 std::ios_base::ate str() , std::ios_base::app, std::ios_base::trunc, std::ios_base::binary .
:
The level of support for the open modes other than std::ios_base::in and std::ios_base::out varies among implementations. C++11 explicitly specifies the support for std::ios_base::ate in str() and in this constructor, but std::ios_base::app, std::ios_base::trunc, and std::ios_base::binary have different effects on different implementations.
Google.
. .

basic_stringbuf .
:
Demonstrates calling the constructor of basic_stringbuf directly.
Google.
. .

#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';
}

:

1
test1
est12 (Sun Studio) 2st1 (GCC)

.

:
constructs the string stream
Google.
. .

(public - std::basic_stringstream) []

Web Proxy Viewer  |  New URL  |  Original Page