- tmp/tmpj10z49d5/{from.md → to.md} +105 -104
tmp/tmpj10z49d5/{from.md → to.md}
RENAMED
|
@@ -1,90 +1,89 @@
|
|
| 1 |
## String-based streams <a id="string.streams">[[string.streams]]</a>
|
| 2 |
|
| 3 |
-
###
|
| 4 |
-
|
| 5 |
-
The header `<sstream>` defines four class templates and eight types that
|
| 6 |
-
associate stream buffers with objects of class `basic_string`, as
|
| 7 |
-
described in [[string.classes]].
|
| 8 |
|
| 9 |
``` cpp
|
| 10 |
namespace std {
|
| 11 |
template <class charT, class traits = char_traits<charT>,
|
| 12 |
class Allocator = allocator<charT>>
|
| 13 |
class basic_stringbuf;
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
template <class charT, class traits = char_traits<charT>,
|
| 19 |
class Allocator = allocator<charT>>
|
| 20 |
class basic_istringstream;
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
template <class charT, class traits = char_traits<charT>,
|
| 26 |
class Allocator = allocator<charT>>
|
| 27 |
class basic_ostringstream;
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
template <class charT, class traits = char_traits<charT>,
|
| 32 |
class Allocator = allocator<charT>>
|
| 33 |
class basic_stringstream;
|
| 34 |
-
|
| 35 |
-
|
| 36 |
}
|
| 37 |
```
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
### Class template `basic_stringbuf` <a id="stringbuf">[[stringbuf]]</a>
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
namespace std {
|
| 43 |
template <class charT, class traits = char_traits<charT>,
|
| 44 |
class Allocator = allocator<charT>>
|
| 45 |
class basic_stringbuf : public basic_streambuf<charT, traits> {
|
| 46 |
public:
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
-
// [stringbuf.cons]
|
| 55 |
-
explicit basic_stringbuf(
|
| 56 |
-
|
| 57 |
-
explicit basic_stringbuf
|
| 58 |
-
|
| 59 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 60 |
basic_stringbuf(const basic_stringbuf& rhs) = delete;
|
| 61 |
basic_stringbuf(basic_stringbuf&& rhs);
|
| 62 |
|
| 63 |
-
// [stringbuf.assign]
|
| 64 |
basic_stringbuf& operator=(const basic_stringbuf& rhs) = delete;
|
| 65 |
basic_stringbuf& operator=(basic_stringbuf&& rhs);
|
| 66 |
void swap(basic_stringbuf& rhs);
|
| 67 |
|
| 68 |
-
// [stringbuf.members]
|
| 69 |
basic_string<charT, traits, Allocator> str() const;
|
| 70 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 71 |
|
| 72 |
protected:
|
| 73 |
-
// [stringbuf.virtuals]
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
| 80 |
-
virtual pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 81 |
ios_base::openmode which
|
| 82 |
-
|
| 83 |
-
|
| 84 |
ios_base::openmode which
|
| 85 |
-
|
| 86 |
|
| 87 |
private:
|
| 88 |
ios_base::openmode mode; // exposition only
|
| 89 |
};
|
| 90 |
|
|
@@ -106,22 +105,23 @@ For the sake of exposition, the maintained data is presented here as:
|
|
| 106 |
read, and `out` set if the output sequence can be written.
|
| 107 |
|
| 108 |
#### `basic_stringbuf` constructors <a id="stringbuf.cons">[[stringbuf.cons]]</a>
|
| 109 |
|
| 110 |
``` cpp
|
| 111 |
-
explicit basic_stringbuf(
|
| 112 |
-
|
| 113 |
```
|
| 114 |
|
| 115 |
*Effects:* Constructs an object of class `basic_stringbuf`, initializing
|
| 116 |
the base class with `basic_streambuf()` ([[streambuf.cons]]), and
|
| 117 |
initializing `mode` with `which`.
|
| 118 |
|
| 119 |
-
`str() == ""`.
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
-
explicit basic_stringbuf(
|
|
|
|
| 123 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 124 |
```
|
| 125 |
|
| 126 |
*Effects:* Constructs an object of class `basic_stringbuf`, initializing
|
| 127 |
the base class with `basic_streambuf()` ([[streambuf.cons]]), and
|
|
@@ -176,11 +176,11 @@ void swap(basic_stringbuf& rhs);
|
|
| 176 |
template <class charT, class traits, class Allocator>
|
| 177 |
void swap(basic_stringbuf<charT, traits, Allocator>& x,
|
| 178 |
basic_stringbuf<charT, traits, Allocator>& y);
|
| 179 |
```
|
| 180 |
|
| 181 |
-
*Effects:* `x.swap(y)`.
|
| 182 |
|
| 183 |
#### Member functions <a id="stringbuf.members">[[stringbuf.members]]</a>
|
| 184 |
|
| 185 |
``` cpp
|
| 186 |
basic_string<charT, traits, Allocator> str() const;
|
|
@@ -189,11 +189,11 @@ basic_string<charT,traits,Allocator> str() const;
|
|
| 189 |
*Returns:* A `basic_string` object whose content is equal to the
|
| 190 |
`basic_stringbuf` underlying character sequence. If the
|
| 191 |
`basic_stringbuf` was created only in input mode, the resultant
|
| 192 |
`basic_string` contains the character sequence in the range \[`eback()`,
|
| 193 |
`egptr()`). If the `basic_stringbuf` was created with
|
| 194 |
-
`which & ios_base::out` being
|
| 195 |
contains the character sequence in the range \[`pbase()`, `high_mark`),
|
| 196 |
where `high_mark` represents the position one past the highest
|
| 197 |
initialized character in the buffer. Characters can be initialized by
|
| 198 |
writing to the stream, by constructing the `basic_stringbuf` with a
|
| 199 |
`basic_string`, or by calling the `str(basic_string)` member function.
|
|
@@ -210,31 +210,31 @@ void str(const basic_string<charT,traits,Allocator>& s);
|
|
| 210 |
|
| 211 |
*Effects:* Copies the content of `s` into the `basic_stringbuf`
|
| 212 |
underlying character sequence and initializes the input and output
|
| 213 |
sequences according to `mode`.
|
| 214 |
|
| 215 |
-
*Postconditions:* If `mode & ios_base::out` is
|
| 216 |
-
the first underlying character and `epptr()` `>= pbase() + s.size()`
|
| 217 |
-
holds; in addition, if `mode & ios_base::ate` is
|
| 218 |
`pptr() == pbase() + s.size()` holds, otherwise `pptr() == pbase()` is
|
| 219 |
-
true. If `mode & ios_base::in` is
|
| 220 |
-
underlying character, and both `gptr() == eback()` and
|
| 221 |
`egptr() == eback() + s.size()` hold.
|
| 222 |
|
| 223 |
#### Overridden virtual functions <a id="stringbuf.virtuals">[[stringbuf.virtuals]]</a>
|
| 224 |
|
| 225 |
``` cpp
|
| 226 |
-
int_type underflow();
|
| 227 |
```
|
| 228 |
|
| 229 |
*Returns:* If the input sequence has a read position available, returns
|
| 230 |
`traits::to_int_type(*gptr())`. Otherwise, returns `traits::eof()`. Any
|
| 231 |
character in the underlying buffer which has been initialized is
|
| 232 |
considered to be part of the input sequence.
|
| 233 |
|
| 234 |
``` cpp
|
| 235 |
-
int_type pbackfail(int_type c = traits::eof());
|
| 236 |
```
|
| 237 |
|
| 238 |
*Effects:* Puts back the character designated by `c` to the input
|
| 239 |
sequence, if possible, in one of three ways:
|
| 240 |
|
|
@@ -253,11 +253,11 @@ sequence, if possible, in one of three ways:
|
|
| 253 |
|
| 254 |
*Remarks:* If the function can succeed in more than one of these ways,
|
| 255 |
it is unspecified which way is chosen.
|
| 256 |
|
| 257 |
``` cpp
|
| 258 |
-
int_type overflow(int_type c = traits::eof());
|
| 259 |
```
|
| 260 |
|
| 261 |
*Effects:* Appends the character designated by `c` to the output
|
| 262 |
sequence, if possible, in one of two ways:
|
| 263 |
|
|
@@ -283,11 +283,11 @@ plus at least one additional write position. If
|
|
| 283 |
`egptr()` to point just past the new write position.
|
| 284 |
|
| 285 |
``` cpp
|
| 286 |
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 287 |
ios_base::openmode which
|
| 288 |
-
= ios_base::in | ios_base::out);
|
| 289 |
```
|
| 290 |
|
| 291 |
*Effects:* Alters the stream position within one of the controlled
|
| 292 |
sequences, if possible, as indicated in
|
| 293 |
Table [[tab:iostreams.seekoff.positioning]].
|
|
@@ -315,23 +315,24 @@ as indicated in Table [[tab:iostreams.newoff.values]].
|
|
| 315 |
| `way == ios_base::cur` | the next pointer minus the beginning pointer (`xnext - xbeg`). |
|
| 316 |
| `way == ios_base::end` | the high mark pointer minus the beginning pointer (`high_mark - xbeg`). |
|
| 317 |
|
| 318 |
|
| 319 |
If `(newoff + off) < 0`, or if `newoff + off` refers to an uninitialized
|
| 320 |
-
character (
|
| 321 |
-
|
| 322 |
-
|
| 323 |
|
| 324 |
*Returns:* `pos_type(newoff)`, constructed from the resultant offset
|
| 325 |
`newoff` (of type `off_type`), that stores the resultant stream
|
| 326 |
position, if possible. If the positioning operation fails, or if the
|
| 327 |
constructed object cannot represent the resultant stream position, the
|
| 328 |
return value is `pos_type(off_type(-1))`.
|
| 329 |
|
| 330 |
``` cpp
|
| 331 |
-
pos_type seekpos(pos_type sp,
|
| 332 |
-
|
|
|
|
| 333 |
```
|
| 334 |
|
| 335 |
*Effects:* Equivalent to `seekoff(off_type(sp), ios_base::beg, which)`.
|
| 336 |
|
| 337 |
*Returns:* `sp` to indicate success, or `pos_type(off_type(-1))` to
|
|
@@ -352,31 +353,32 @@ effect.
|
|
| 352 |
namespace std {
|
| 353 |
template <class charT, class traits = char_traits<charT>,
|
| 354 |
class Allocator = allocator<charT>>
|
| 355 |
class basic_istringstream : public basic_istream<charT, traits> {
|
| 356 |
public:
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
|
| 364 |
-
// [istringstream.cons]
|
| 365 |
-
explicit basic_istringstream(
|
|
|
|
| 366 |
explicit basic_istringstream(
|
| 367 |
const basic_string<charT, traits, Allocator>& str,
|
| 368 |
ios_base::openmode which = ios_base::in);
|
| 369 |
basic_istringstream(const basic_istringstream& rhs) = delete;
|
| 370 |
basic_istringstream(basic_istringstream&& rhs);
|
| 371 |
|
| 372 |
-
// [istringstream.assign]
|
| 373 |
basic_istringstream& operator=(const basic_istringstream& rhs) = delete;
|
| 374 |
basic_istringstream& operator=(basic_istringstream&& rhs);
|
| 375 |
void swap(basic_istringstream& rhs);
|
| 376 |
|
| 377 |
-
// [istringstream.members]
|
| 378 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 379 |
|
| 380 |
basic_string<charT, traits, Allocator> str() const;
|
| 381 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 382 |
private:
|
|
@@ -423,12 +425,12 @@ explicit basic_istringstream(
|
|
| 423 |
basic_istringstream(basic_istringstream&& rhs);
|
| 424 |
```
|
| 425 |
|
| 426 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 427 |
by move constructing the base class, and the contained
|
| 428 |
-
`basic_stringbuf`. Next `basic_istream<charT,traits>::set_rdbuf(&sb)`
|
| 429 |
-
called to install the contained `basic_stringbuf`.
|
| 430 |
|
| 431 |
#### Assign and swap <a id="istringstream.assign">[[istringstream.assign]]</a>
|
| 432 |
|
| 433 |
``` cpp
|
| 434 |
basic_istringstream& operator=(basic_istringstream&& rhs);
|
|
@@ -450,19 +452,20 @@ void swap(basic_istringstream& rhs);
|
|
| 450 |
template <class charT, class traits, class Allocator>
|
| 451 |
void swap(basic_istringstream<charT, traits, Allocator>& x,
|
| 452 |
basic_istringstream<charT, traits, Allocator>& y);
|
| 453 |
```
|
| 454 |
|
| 455 |
-
*Effects:* `x.swap(y)`.
|
| 456 |
|
| 457 |
#### Member functions <a id="istringstream.members">[[istringstream.members]]</a>
|
| 458 |
|
| 459 |
``` cpp
|
| 460 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 461 |
```
|
| 462 |
|
| 463 |
-
*Returns:*
|
|
|
|
| 464 |
|
| 465 |
``` cpp
|
| 466 |
basic_string<charT, traits, Allocator> str() const;
|
| 467 |
```
|
| 468 |
|
|
@@ -480,33 +483,32 @@ void str(const basic_string<charT,traits,Allocator>& s);
|
|
| 480 |
namespace std {
|
| 481 |
template <class charT, class traits = char_traits<charT>,
|
| 482 |
class Allocator = allocator<charT>>
|
| 483 |
class basic_ostringstream : public basic_ostream<charT, traits> {
|
| 484 |
public:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
|
| 486 |
-
//
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
typedef typename traits::pos_type pos_type;
|
| 490 |
-
typedef typename traits::off_type off_type;
|
| 491 |
-
typedef traits traits_type;
|
| 492 |
-
typedef Allocator allocator_type;
|
| 493 |
-
|
| 494 |
-
// [ostringstream.cons] Constructors/destructor:
|
| 495 |
-
explicit basic_ostringstream(ios_base::openmode which = ios_base::out);
|
| 496 |
explicit basic_ostringstream(
|
| 497 |
const basic_string<charT, traits, Allocator>& str,
|
| 498 |
ios_base::openmode which = ios_base::out);
|
| 499 |
basic_ostringstream(const basic_ostringstream& rhs) = delete;
|
| 500 |
basic_ostringstream(basic_ostringstream&& rhs);
|
| 501 |
|
| 502 |
-
// [ostringstream.assign]
|
| 503 |
basic_ostringstream& operator=(const basic_ostringstream& rhs) = delete;
|
| 504 |
basic_ostringstream& operator=(basic_ostringstream&& rhs);
|
| 505 |
void swap(basic_ostringstream& rhs);
|
| 506 |
|
| 507 |
-
// [ostringstream.members]
|
| 508 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 509 |
|
| 510 |
basic_string<charT, traits, Allocator> str() const;
|
| 511 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 512 |
private:
|
|
@@ -527,11 +529,12 @@ the sake of exposition, the maintained data is presented here as:
|
|
| 527 |
- `sb`, the `stringbuf` object.
|
| 528 |
|
| 529 |
#### `basic_ostringstream` constructors <a id="ostringstream.cons">[[ostringstream.cons]]</a>
|
| 530 |
|
| 531 |
``` cpp
|
| 532 |
-
explicit basic_ostringstream(
|
|
|
|
| 533 |
```
|
| 534 |
|
| 535 |
*Effects:* Constructs an object of class `basic_ostringstream`,
|
| 536 |
initializing the base class with `basic_ostream(&sb)` and initializing
|
| 537 |
`sb` with
|
|
@@ -552,12 +555,12 @@ explicit basic_ostringstream(
|
|
| 552 |
basic_ostringstream(basic_ostringstream&& rhs);
|
| 553 |
```
|
| 554 |
|
| 555 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 556 |
by move constructing the base class, and the contained
|
| 557 |
-
`basic_stringbuf`. Next `basic_ostream<charT,traits>::set_rdbuf(&sb)`
|
| 558 |
-
called to install the contained `basic_stringbuf`.
|
| 559 |
|
| 560 |
#### Assign and swap <a id="ostringstream.assign">[[ostringstream.assign]]</a>
|
| 561 |
|
| 562 |
``` cpp
|
| 563 |
basic_ostringstream& operator=(basic_ostringstream&& rhs);
|
|
@@ -579,19 +582,20 @@ void swap(basic_ostringstream& rhs);
|
|
| 579 |
template <class charT, class traits, class Allocator>
|
| 580 |
void swap(basic_ostringstream<charT, traits, Allocator>& x,
|
| 581 |
basic_ostringstream<charT, traits, Allocator>& y);
|
| 582 |
```
|
| 583 |
|
| 584 |
-
*Effects:* `x.swap(y)`.
|
| 585 |
|
| 586 |
#### Member functions <a id="ostringstream.members">[[ostringstream.members]]</a>
|
| 587 |
|
| 588 |
``` cpp
|
| 589 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 590 |
```
|
| 591 |
|
| 592 |
-
*Returns:*
|
|
|
|
| 593 |
|
| 594 |
``` cpp
|
| 595 |
basic_string<charT, traits, Allocator> str() const;
|
| 596 |
```
|
| 597 |
|
|
@@ -607,37 +611,34 @@ void str(const basic_string<charT,traits,Allocator>& s);
|
|
| 607 |
|
| 608 |
``` cpp
|
| 609 |
namespace std {
|
| 610 |
template <class charT, class traits = char_traits<charT>,
|
| 611 |
class Allocator = allocator<charT>>
|
| 612 |
-
class basic_stringstream
|
| 613 |
-
: public basic_iostream<charT,traits> {
|
| 614 |
public:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 615 |
|
| 616 |
-
//
|
| 617 |
-
typedef charT char_type;
|
| 618 |
-
typedef typename traits::int_type int_type;
|
| 619 |
-
typedef typename traits::pos_type pos_type;
|
| 620 |
-
typedef typename traits::off_type off_type;
|
| 621 |
-
typedef traits traits_type;
|
| 622 |
-
typedef Allocator allocator_type;
|
| 623 |
-
|
| 624 |
-
// constructors/destructor
|
| 625 |
explicit basic_stringstream(
|
| 626 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 627 |
explicit basic_stringstream(
|
| 628 |
const basic_string<charT, traits, Allocator>& str,
|
| 629 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 630 |
basic_stringstream(const basic_stringstream& rhs) = delete;
|
| 631 |
basic_stringstream(basic_stringstream&& rhs);
|
| 632 |
|
| 633 |
-
// [stringstream.assign]
|
| 634 |
basic_stringstream& operator=(const basic_stringstream& rhs) = delete;
|
| 635 |
basic_stringstream& operator=(basic_stringstream&& rhs);
|
| 636 |
void swap(basic_stringstream& rhs);
|
| 637 |
|
| 638 |
-
//
|
| 639 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 640 |
basic_string<charT, traits, Allocator> str() const;
|
| 641 |
void str(const basic_string<charT, traits, Allocator>& str);
|
| 642 |
|
| 643 |
private:
|
|
@@ -657,11 +658,11 @@ and writing from objects of class
|
|
| 657 |
associated sequence. For the sake of exposition, the maintained data is
|
| 658 |
presented here as
|
| 659 |
|
| 660 |
- `sb`, the `stringbuf` object.
|
| 661 |
|
| 662 |
-
#### basic_stringstream constructors <a id="stringstream.cons">[[stringstream.cons]]</a>
|
| 663 |
|
| 664 |
``` cpp
|
| 665 |
explicit basic_stringstream(
|
| 666 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 667 |
```
|
|
@@ -686,12 +687,12 @@ explicit basic_stringstream(
|
|
| 686 |
basic_stringstream(basic_stringstream&& rhs);
|
| 687 |
```
|
| 688 |
|
| 689 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 690 |
by move constructing the base class, and the contained
|
| 691 |
-
`basic_stringbuf`. Next `basic_istream<charT,traits>::set_rdbuf(&sb)`
|
| 692 |
-
called to install the contained `basic_stringbuf`.
|
| 693 |
|
| 694 |
#### Assign and swap <a id="stringstream.assign">[[stringstream.assign]]</a>
|
| 695 |
|
| 696 |
``` cpp
|
| 697 |
basic_stringstream& operator=(basic_stringstream&& rhs);
|
|
@@ -713,11 +714,11 @@ void swap(basic_stringstream& rhs);
|
|
| 713 |
template <class charT, class traits, class Allocator>
|
| 714 |
void swap(basic_stringstream<charT, traits, Allocator>& x,
|
| 715 |
basic_stringstream<charT, traits, Allocator>& y);
|
| 716 |
```
|
| 717 |
|
| 718 |
-
*Effects:* `x.swap(y)`.
|
| 719 |
|
| 720 |
#### Member functions <a id="stringstream.members">[[stringstream.members]]</a>
|
| 721 |
|
| 722 |
``` cpp
|
| 723 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
|
|
|
| 1 |
## String-based streams <a id="string.streams">[[string.streams]]</a>
|
| 2 |
|
| 3 |
+
### Header `<sstream>` synopsis <a id="sstream.syn">[[sstream.syn]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
namespace std {
|
| 7 |
template <class charT, class traits = char_traits<charT>,
|
| 8 |
class Allocator = allocator<charT>>
|
| 9 |
class basic_stringbuf;
|
| 10 |
|
| 11 |
+
using stringbuf = basic_stringbuf<char>;
|
| 12 |
+
using wstringbuf = basic_stringbuf<wchar_t>;
|
| 13 |
|
| 14 |
template <class charT, class traits = char_traits<charT>,
|
| 15 |
class Allocator = allocator<charT>>
|
| 16 |
class basic_istringstream;
|
| 17 |
|
| 18 |
+
using istringstream = basic_istringstream<char>;
|
| 19 |
+
using wistringstream = basic_istringstream<wchar_t>;
|
| 20 |
|
| 21 |
template <class charT, class traits = char_traits<charT>,
|
| 22 |
class Allocator = allocator<charT>>
|
| 23 |
class basic_ostringstream;
|
| 24 |
+
using ostringstream = basic_ostringstream<char>;
|
| 25 |
+
using wostringstream = basic_ostringstream<wchar_t>;
|
| 26 |
|
| 27 |
template <class charT, class traits = char_traits<charT>,
|
| 28 |
class Allocator = allocator<charT>>
|
| 29 |
class basic_stringstream;
|
| 30 |
+
using stringstream = basic_stringstream<char>;
|
| 31 |
+
using wstringstream = basic_stringstream<wchar_t>;
|
| 32 |
}
|
| 33 |
```
|
| 34 |
|
| 35 |
+
The header `<sstream>` defines four class templates and eight types that
|
| 36 |
+
associate stream buffers with objects of class `basic_string`, as
|
| 37 |
+
described in [[string.classes]].
|
| 38 |
+
|
| 39 |
### Class template `basic_stringbuf` <a id="stringbuf">[[stringbuf]]</a>
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
namespace std {
|
| 43 |
template <class charT, class traits = char_traits<charT>,
|
| 44 |
class Allocator = allocator<charT>>
|
| 45 |
class basic_stringbuf : public basic_streambuf<charT, traits> {
|
| 46 |
public:
|
| 47 |
+
using char_type = charT;
|
| 48 |
+
using int_type = typename traits::int_type;
|
| 49 |
+
using pos_type = typename traits::pos_type;
|
| 50 |
+
using off_type = typename traits::off_type;
|
| 51 |
+
using traits_type = traits;
|
| 52 |
+
using allocator_type = Allocator;
|
| 53 |
|
| 54 |
+
// [stringbuf.cons], constructors
|
| 55 |
+
explicit basic_stringbuf(
|
| 56 |
+
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 57 |
+
explicit basic_stringbuf(
|
| 58 |
+
const basic_string<charT, traits, Allocator>& str,
|
| 59 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 60 |
basic_stringbuf(const basic_stringbuf& rhs) = delete;
|
| 61 |
basic_stringbuf(basic_stringbuf&& rhs);
|
| 62 |
|
| 63 |
+
// [stringbuf.assign], assign and swap
|
| 64 |
basic_stringbuf& operator=(const basic_stringbuf& rhs) = delete;
|
| 65 |
basic_stringbuf& operator=(basic_stringbuf&& rhs);
|
| 66 |
void swap(basic_stringbuf& rhs);
|
| 67 |
|
| 68 |
+
// [stringbuf.members], get and set
|
| 69 |
basic_string<charT, traits, Allocator> str() const;
|
| 70 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 71 |
|
| 72 |
protected:
|
| 73 |
+
// [stringbuf.virtuals], overridden virtual functions
|
| 74 |
+
int_type underflow() override;
|
| 75 |
+
int_type pbackfail(int_type c = traits::eof()) override;
|
| 76 |
+
int_type overflow (int_type c = traits::eof()) override;
|
| 77 |
+
basic_streambuf<charT, traits>* setbuf(charT*, streamsize) override;
|
| 78 |
|
| 79 |
+
pos_type seekoff(off_type off, ios_base::seekdir way,
|
|
|
|
| 80 |
ios_base::openmode which
|
| 81 |
+
= ios_base::in | ios_base::out) override;
|
| 82 |
+
pos_type seekpos(pos_type sp,
|
| 83 |
ios_base::openmode which
|
| 84 |
+
= ios_base::in | ios_base::out) override;
|
| 85 |
|
| 86 |
private:
|
| 87 |
ios_base::openmode mode; // exposition only
|
| 88 |
};
|
| 89 |
|
|
|
|
| 105 |
read, and `out` set if the output sequence can be written.
|
| 106 |
|
| 107 |
#### `basic_stringbuf` constructors <a id="stringbuf.cons">[[stringbuf.cons]]</a>
|
| 108 |
|
| 109 |
``` cpp
|
| 110 |
+
explicit basic_stringbuf(
|
| 111 |
+
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 112 |
```
|
| 113 |
|
| 114 |
*Effects:* Constructs an object of class `basic_stringbuf`, initializing
|
| 115 |
the base class with `basic_streambuf()` ([[streambuf.cons]]), and
|
| 116 |
initializing `mode` with `which`.
|
| 117 |
|
| 118 |
+
*Postconditions:* `str() == ""`.
|
| 119 |
|
| 120 |
``` cpp
|
| 121 |
+
explicit basic_stringbuf(
|
| 122 |
+
const basic_string<charT, traits, Allocator>& s,
|
| 123 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 124 |
```
|
| 125 |
|
| 126 |
*Effects:* Constructs an object of class `basic_stringbuf`, initializing
|
| 127 |
the base class with `basic_streambuf()` ([[streambuf.cons]]), and
|
|
|
|
| 176 |
template <class charT, class traits, class Allocator>
|
| 177 |
void swap(basic_stringbuf<charT, traits, Allocator>& x,
|
| 178 |
basic_stringbuf<charT, traits, Allocator>& y);
|
| 179 |
```
|
| 180 |
|
| 181 |
+
*Effects:* As if by `x.swap(y)`.
|
| 182 |
|
| 183 |
#### Member functions <a id="stringbuf.members">[[stringbuf.members]]</a>
|
| 184 |
|
| 185 |
``` cpp
|
| 186 |
basic_string<charT, traits, Allocator> str() const;
|
|
|
|
| 189 |
*Returns:* A `basic_string` object whose content is equal to the
|
| 190 |
`basic_stringbuf` underlying character sequence. If the
|
| 191 |
`basic_stringbuf` was created only in input mode, the resultant
|
| 192 |
`basic_string` contains the character sequence in the range \[`eback()`,
|
| 193 |
`egptr()`). If the `basic_stringbuf` was created with
|
| 194 |
+
`which & ios_base::out` being nonzero then the resultant `basic_string`
|
| 195 |
contains the character sequence in the range \[`pbase()`, `high_mark`),
|
| 196 |
where `high_mark` represents the position one past the highest
|
| 197 |
initialized character in the buffer. Characters can be initialized by
|
| 198 |
writing to the stream, by constructing the `basic_stringbuf` with a
|
| 199 |
`basic_string`, or by calling the `str(basic_string)` member function.
|
|
|
|
| 210 |
|
| 211 |
*Effects:* Copies the content of `s` into the `basic_stringbuf`
|
| 212 |
underlying character sequence and initializes the input and output
|
| 213 |
sequences according to `mode`.
|
| 214 |
|
| 215 |
+
*Postconditions:* If `mode & ios_base::out` is nonzero, `pbase()` points
|
| 216 |
+
to the first underlying character and `epptr()` `>= pbase() + s.size()`
|
| 217 |
+
holds; in addition, if `mode & ios_base::ate` is nonzero,
|
| 218 |
`pptr() == pbase() + s.size()` holds, otherwise `pptr() == pbase()` is
|
| 219 |
+
`true`. If `mode & ios_base::in` is nonzero, `eback()` points to the
|
| 220 |
+
first underlying character, and both `gptr() == eback()` and
|
| 221 |
`egptr() == eback() + s.size()` hold.
|
| 222 |
|
| 223 |
#### Overridden virtual functions <a id="stringbuf.virtuals">[[stringbuf.virtuals]]</a>
|
| 224 |
|
| 225 |
``` cpp
|
| 226 |
+
int_type underflow() override;
|
| 227 |
```
|
| 228 |
|
| 229 |
*Returns:* If the input sequence has a read position available, returns
|
| 230 |
`traits::to_int_type(*gptr())`. Otherwise, returns `traits::eof()`. Any
|
| 231 |
character in the underlying buffer which has been initialized is
|
| 232 |
considered to be part of the input sequence.
|
| 233 |
|
| 234 |
``` cpp
|
| 235 |
+
int_type pbackfail(int_type c = traits::eof()) override;
|
| 236 |
```
|
| 237 |
|
| 238 |
*Effects:* Puts back the character designated by `c` to the input
|
| 239 |
sequence, if possible, in one of three ways:
|
| 240 |
|
|
|
|
| 253 |
|
| 254 |
*Remarks:* If the function can succeed in more than one of these ways,
|
| 255 |
it is unspecified which way is chosen.
|
| 256 |
|
| 257 |
``` cpp
|
| 258 |
+
int_type overflow(int_type c = traits::eof()) override;
|
| 259 |
```
|
| 260 |
|
| 261 |
*Effects:* Appends the character designated by `c` to the output
|
| 262 |
sequence, if possible, in one of two ways:
|
| 263 |
|
|
|
|
| 283 |
`egptr()` to point just past the new write position.
|
| 284 |
|
| 285 |
``` cpp
|
| 286 |
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 287 |
ios_base::openmode which
|
| 288 |
+
= ios_base::in | ios_base::out) override;
|
| 289 |
```
|
| 290 |
|
| 291 |
*Effects:* Alters the stream position within one of the controlled
|
| 292 |
sequences, if possible, as indicated in
|
| 293 |
Table [[tab:iostreams.seekoff.positioning]].
|
|
|
|
| 315 |
| `way == ios_base::cur` | the next pointer minus the beginning pointer (`xnext - xbeg`). |
|
| 316 |
| `way == ios_base::end` | the high mark pointer minus the beginning pointer (`high_mark - xbeg`). |
|
| 317 |
|
| 318 |
|
| 319 |
If `(newoff + off) < 0`, or if `newoff + off` refers to an uninitialized
|
| 320 |
+
character ([[stringbuf.members]]), the positioning operation fails.
|
| 321 |
+
Otherwise, the function assigns `xbeg + newoff + off` to the next
|
| 322 |
+
pointer `xnext`.
|
| 323 |
|
| 324 |
*Returns:* `pos_type(newoff)`, constructed from the resultant offset
|
| 325 |
`newoff` (of type `off_type`), that stores the resultant stream
|
| 326 |
position, if possible. If the positioning operation fails, or if the
|
| 327 |
constructed object cannot represent the resultant stream position, the
|
| 328 |
return value is `pos_type(off_type(-1))`.
|
| 329 |
|
| 330 |
``` cpp
|
| 331 |
+
pos_type seekpos(pos_type sp,
|
| 332 |
+
ios_base::openmode which
|
| 333 |
+
= ios_base::in | ios_base::out) override;
|
| 334 |
```
|
| 335 |
|
| 336 |
*Effects:* Equivalent to `seekoff(off_type(sp), ios_base::beg, which)`.
|
| 337 |
|
| 338 |
*Returns:* `sp` to indicate success, or `pos_type(off_type(-1))` to
|
|
|
|
| 353 |
namespace std {
|
| 354 |
template <class charT, class traits = char_traits<charT>,
|
| 355 |
class Allocator = allocator<charT>>
|
| 356 |
class basic_istringstream : public basic_istream<charT, traits> {
|
| 357 |
public:
|
| 358 |
+
using char_type = charT;
|
| 359 |
+
using int_type = typename traits::int_type;
|
| 360 |
+
using pos_type = typename traits::pos_type;
|
| 361 |
+
using off_type = typename traits::off_type;
|
| 362 |
+
using traits_type = traits;
|
| 363 |
+
using allocator_type = Allocator;
|
| 364 |
|
| 365 |
+
// [istringstream.cons], constructors
|
| 366 |
+
explicit basic_istringstream(
|
| 367 |
+
ios_base::openmode which = ios_base::in);
|
| 368 |
explicit basic_istringstream(
|
| 369 |
const basic_string<charT, traits, Allocator>& str,
|
| 370 |
ios_base::openmode which = ios_base::in);
|
| 371 |
basic_istringstream(const basic_istringstream& rhs) = delete;
|
| 372 |
basic_istringstream(basic_istringstream&& rhs);
|
| 373 |
|
| 374 |
+
// [istringstream.assign], assign and swap
|
| 375 |
basic_istringstream& operator=(const basic_istringstream& rhs) = delete;
|
| 376 |
basic_istringstream& operator=(basic_istringstream&& rhs);
|
| 377 |
void swap(basic_istringstream& rhs);
|
| 378 |
|
| 379 |
+
// [istringstream.members], members
|
| 380 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 381 |
|
| 382 |
basic_string<charT, traits, Allocator> str() const;
|
| 383 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 384 |
private:
|
|
|
|
| 425 |
basic_istringstream(basic_istringstream&& rhs);
|
| 426 |
```
|
| 427 |
|
| 428 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 429 |
by move constructing the base class, and the contained
|
| 430 |
+
`basic_stringbuf`. Next `basic_istream<charT, traits>::set_rdbuf(&sb)`
|
| 431 |
+
is called to install the contained `basic_stringbuf`.
|
| 432 |
|
| 433 |
#### Assign and swap <a id="istringstream.assign">[[istringstream.assign]]</a>
|
| 434 |
|
| 435 |
``` cpp
|
| 436 |
basic_istringstream& operator=(basic_istringstream&& rhs);
|
|
|
|
| 452 |
template <class charT, class traits, class Allocator>
|
| 453 |
void swap(basic_istringstream<charT, traits, Allocator>& x,
|
| 454 |
basic_istringstream<charT, traits, Allocator>& y);
|
| 455 |
```
|
| 456 |
|
| 457 |
+
*Effects:* As if by `x.swap(y)`.
|
| 458 |
|
| 459 |
#### Member functions <a id="istringstream.members">[[istringstream.members]]</a>
|
| 460 |
|
| 461 |
``` cpp
|
| 462 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 463 |
```
|
| 464 |
|
| 465 |
+
*Returns:*
|
| 466 |
+
`const_cast<basic_stringbuf<charT, traits, Allocator>*>(&sb)`.
|
| 467 |
|
| 468 |
``` cpp
|
| 469 |
basic_string<charT, traits, Allocator> str() const;
|
| 470 |
```
|
| 471 |
|
|
|
|
| 483 |
namespace std {
|
| 484 |
template <class charT, class traits = char_traits<charT>,
|
| 485 |
class Allocator = allocator<charT>>
|
| 486 |
class basic_ostringstream : public basic_ostream<charT, traits> {
|
| 487 |
public:
|
| 488 |
+
using char_type = charT;
|
| 489 |
+
using int_type = typename traits::int_type;
|
| 490 |
+
using pos_type = typename traits::pos_type;
|
| 491 |
+
using off_type = typename traits::off_type;
|
| 492 |
+
using traits_type = traits;
|
| 493 |
+
using allocator_type = Allocator;
|
| 494 |
|
| 495 |
+
// [ostringstream.cons], constructors
|
| 496 |
+
explicit basic_ostringstream(
|
| 497 |
+
ios_base::openmode which = ios_base::out);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
explicit basic_ostringstream(
|
| 499 |
const basic_string<charT, traits, Allocator>& str,
|
| 500 |
ios_base::openmode which = ios_base::out);
|
| 501 |
basic_ostringstream(const basic_ostringstream& rhs) = delete;
|
| 502 |
basic_ostringstream(basic_ostringstream&& rhs);
|
| 503 |
|
| 504 |
+
// [ostringstream.assign], assign and swap
|
| 505 |
basic_ostringstream& operator=(const basic_ostringstream& rhs) = delete;
|
| 506 |
basic_ostringstream& operator=(basic_ostringstream&& rhs);
|
| 507 |
void swap(basic_ostringstream& rhs);
|
| 508 |
|
| 509 |
+
// [ostringstream.members], members
|
| 510 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 511 |
|
| 512 |
basic_string<charT, traits, Allocator> str() const;
|
| 513 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 514 |
private:
|
|
|
|
| 529 |
- `sb`, the `stringbuf` object.
|
| 530 |
|
| 531 |
#### `basic_ostringstream` constructors <a id="ostringstream.cons">[[ostringstream.cons]]</a>
|
| 532 |
|
| 533 |
``` cpp
|
| 534 |
+
explicit basic_ostringstream(
|
| 535 |
+
ios_base::openmode which = ios_base::out);
|
| 536 |
```
|
| 537 |
|
| 538 |
*Effects:* Constructs an object of class `basic_ostringstream`,
|
| 539 |
initializing the base class with `basic_ostream(&sb)` and initializing
|
| 540 |
`sb` with
|
|
|
|
| 555 |
basic_ostringstream(basic_ostringstream&& rhs);
|
| 556 |
```
|
| 557 |
|
| 558 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 559 |
by move constructing the base class, and the contained
|
| 560 |
+
`basic_stringbuf`. Next `basic_ostream<charT, traits>::set_rdbuf(&sb)`
|
| 561 |
+
is called to install the contained `basic_stringbuf`.
|
| 562 |
|
| 563 |
#### Assign and swap <a id="ostringstream.assign">[[ostringstream.assign]]</a>
|
| 564 |
|
| 565 |
``` cpp
|
| 566 |
basic_ostringstream& operator=(basic_ostringstream&& rhs);
|
|
|
|
| 582 |
template <class charT, class traits, class Allocator>
|
| 583 |
void swap(basic_ostringstream<charT, traits, Allocator>& x,
|
| 584 |
basic_ostringstream<charT, traits, Allocator>& y);
|
| 585 |
```
|
| 586 |
|
| 587 |
+
*Effects:* As if by `x.swap(y)`.
|
| 588 |
|
| 589 |
#### Member functions <a id="ostringstream.members">[[ostringstream.members]]</a>
|
| 590 |
|
| 591 |
``` cpp
|
| 592 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 593 |
```
|
| 594 |
|
| 595 |
+
*Returns:*
|
| 596 |
+
`const_cast<basic_stringbuf<charT, traits, Allocator>*>(&sb)`.
|
| 597 |
|
| 598 |
``` cpp
|
| 599 |
basic_string<charT, traits, Allocator> str() const;
|
| 600 |
```
|
| 601 |
|
|
|
|
| 611 |
|
| 612 |
``` cpp
|
| 613 |
namespace std {
|
| 614 |
template <class charT, class traits = char_traits<charT>,
|
| 615 |
class Allocator = allocator<charT>>
|
| 616 |
+
class basic_stringstream : public basic_iostream<charT, traits> {
|
|
|
|
| 617 |
public:
|
| 618 |
+
using char_type = charT;
|
| 619 |
+
using int_type = typename traits::int_type;
|
| 620 |
+
using pos_type = typename traits::pos_type;
|
| 621 |
+
using off_type = typename traits::off_type;
|
| 622 |
+
using traits_type = traits;
|
| 623 |
+
using allocator_type = Allocator;
|
| 624 |
|
| 625 |
+
// [stringstream.cons], constructors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 626 |
explicit basic_stringstream(
|
| 627 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 628 |
explicit basic_stringstream(
|
| 629 |
const basic_string<charT, traits, Allocator>& str,
|
| 630 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 631 |
basic_stringstream(const basic_stringstream& rhs) = delete;
|
| 632 |
basic_stringstream(basic_stringstream&& rhs);
|
| 633 |
|
| 634 |
+
// [stringstream.assign], assign and swap
|
| 635 |
basic_stringstream& operator=(const basic_stringstream& rhs) = delete;
|
| 636 |
basic_stringstream& operator=(basic_stringstream&& rhs);
|
| 637 |
void swap(basic_stringstream& rhs);
|
| 638 |
|
| 639 |
+
// [stringstream.members], members
|
| 640 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 641 |
basic_string<charT, traits, Allocator> str() const;
|
| 642 |
void str(const basic_string<charT, traits, Allocator>& str);
|
| 643 |
|
| 644 |
private:
|
|
|
|
| 658 |
associated sequence. For the sake of exposition, the maintained data is
|
| 659 |
presented here as
|
| 660 |
|
| 661 |
- `sb`, the `stringbuf` object.
|
| 662 |
|
| 663 |
+
#### `basic_stringstream` constructors <a id="stringstream.cons">[[stringstream.cons]]</a>
|
| 664 |
|
| 665 |
``` cpp
|
| 666 |
explicit basic_stringstream(
|
| 667 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 668 |
```
|
|
|
|
| 687 |
basic_stringstream(basic_stringstream&& rhs);
|
| 688 |
```
|
| 689 |
|
| 690 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 691 |
by move constructing the base class, and the contained
|
| 692 |
+
`basic_stringbuf`. Next `basic_istream<charT, traits>::set_rdbuf(&sb)`
|
| 693 |
+
is called to install the contained `basic_stringbuf`.
|
| 694 |
|
| 695 |
#### Assign and swap <a id="stringstream.assign">[[stringstream.assign]]</a>
|
| 696 |
|
| 697 |
``` cpp
|
| 698 |
basic_stringstream& operator=(basic_stringstream&& rhs);
|
|
|
|
| 714 |
template <class charT, class traits, class Allocator>
|
| 715 |
void swap(basic_stringstream<charT, traits, Allocator>& x,
|
| 716 |
basic_stringstream<charT, traits, Allocator>& y);
|
| 717 |
```
|
| 718 |
|
| 719 |
+
*Effects:* As if by `x.swap(y)`.
|
| 720 |
|
| 721 |
#### Member functions <a id="stringstream.members">[[stringstream.members]]</a>
|
| 722 |
|
| 723 |
``` cpp
|
| 724 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|