- tmp/tmpdpy0grum/{from.md → to.md} +288 -207
tmp/tmpdpy0grum/{from.md → to.md}
RENAMED
|
@@ -39,10 +39,17 @@ namespace std {
|
|
| 39 |
template<class charT, class traits>
|
| 40 |
basic_ostream<charT, traits>& ends(basic_ostream<charT, traits>& os);
|
| 41 |
template<class charT, class traits>
|
| 42 |
basic_ostream<charT, traits>& flush(basic_ostream<charT, traits>& os);
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
template<class charT, class traits, class T>
|
| 45 |
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&& os, const T& x);
|
| 46 |
}
|
| 47 |
```
|
| 48 |
|
|
@@ -52,11 +59,11 @@ namespace std {
|
|
| 52 |
namespace std {
|
| 53 |
// types T1, T2, ... are unspecified implementation types
|
| 54 |
T1 resetiosflags(ios_base::fmtflags mask);
|
| 55 |
T2 setiosflags (ios_base::fmtflags mask);
|
| 56 |
T3 setbase(int base);
|
| 57 |
-
template<charT> T4 setfill(charT c);
|
| 58 |
T5 setprecision(int n);
|
| 59 |
T6 setw(int n);
|
| 60 |
template<class moneyT> T7 get_money(moneyT& mon, bool intl = false);
|
| 61 |
template<class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
|
| 62 |
template<class charT> T9 get_time(struct tm* tmb, const charT* fmt);
|
|
@@ -90,22 +97,22 @@ extracts from stream rvalues.
|
|
| 90 |
``` cpp
|
| 91 |
namespace std {
|
| 92 |
template<class charT, class traits = char_traits<charT>>
|
| 93 |
class basic_istream : virtual public basic_ios<charT, traits> {
|
| 94 |
public:
|
| 95 |
-
// types (inherited from basic_ios
|
| 96 |
using char_type = charT;
|
| 97 |
using int_type = typename traits::int_type;
|
| 98 |
using pos_type = typename traits::pos_type;
|
| 99 |
using off_type = typename traits::off_type;
|
| 100 |
using traits_type = traits;
|
| 101 |
|
| 102 |
// [istream.cons], constructor/destructor
|
| 103 |
explicit basic_istream(basic_streambuf<charT, traits>* sb);
|
| 104 |
virtual ~basic_istream();
|
| 105 |
|
| 106 |
-
// [istream
|
| 107 |
class sentry;
|
| 108 |
|
| 109 |
// [istream.formatted], formatted input
|
| 110 |
basic_istream<charT, traits>&
|
| 111 |
operator>>(basic_istream<charT, traits>& (*pf)(basic_istream<charT, traits>&));
|
|
@@ -155,15 +162,15 @@ namespace std {
|
|
| 155 |
basic_istream<charT, traits>& seekg(pos_type);
|
| 156 |
basic_istream<charT, traits>& seekg(off_type, ios_base::seekdir);
|
| 157 |
|
| 158 |
protected:
|
| 159 |
// [istream.cons], copy/move constructor
|
| 160 |
-
basic_istream(const basic_istream&
|
| 161 |
basic_istream(basic_istream&& rhs);
|
| 162 |
|
| 163 |
// [istream.assign], assign and swap
|
| 164 |
-
basic_istream& operator=(const basic_istream&
|
| 165 |
basic_istream& operator=(basic_istream&& rhs);
|
| 166 |
void swap(basic_istream& rhs);
|
| 167 |
};
|
| 168 |
|
| 169 |
// [istream.extractors], character extraction templates
|
|
@@ -172,16 +179,16 @@ namespace std {
|
|
| 172 |
template<class traits>
|
| 173 |
basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, unsigned char&);
|
| 174 |
template<class traits>
|
| 175 |
basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, signed char&);
|
| 176 |
|
| 177 |
-
template<class charT, class traits>
|
| 178 |
-
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, charT
|
| 179 |
-
template<class traits>
|
| 180 |
-
basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, unsigned char
|
| 181 |
-
template<class traits>
|
| 182 |
-
basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, signed char
|
| 183 |
}
|
| 184 |
```
|
| 185 |
|
| 186 |
The class template `basic_istream` defines a number of member function
|
| 187 |
signatures that assist in reading and interpreting input from sequences
|
|
@@ -194,72 +201,67 @@ obtain (or *extract*) input *characters* by calling `rdbuf()->sbumpc()`
|
|
| 194 |
or `rdbuf()->sgetc()`. They may use other public members of `istream`.
|
| 195 |
|
| 196 |
If `rdbuf()->sbumpc()` or `rdbuf()->sgetc()` returns `traits::eof()`,
|
| 197 |
then the input function, except as explicitly noted otherwise, completes
|
| 198 |
its actions and does `setstate(eofbit)`, which may throw
|
| 199 |
-
`ios_base::failure`
|
| 200 |
|
| 201 |
If one of these called functions throws an exception, then unless
|
| 202 |
-
explicitly noted otherwise, the input function sets `badbit` in
|
| 203 |
-
state. If `badbit` is
|
| 204 |
-
the exception without completing its actions, otherwise it does
|
| 205 |
-
throw anything and proceeds as if the called function had returned a
|
| 206 |
failure indication.
|
| 207 |
|
| 208 |
-
#####
|
| 209 |
|
| 210 |
``` cpp
|
| 211 |
explicit basic_istream(basic_streambuf<charT, traits>* sb);
|
| 212 |
```
|
| 213 |
|
| 214 |
-
*Effects:*
|
| 215 |
-
|
| 216 |
-
`basic_ios::init(sb)` ([[basic.ios.cons]]).
|
| 217 |
|
| 218 |
-
*
|
| 219 |
|
| 220 |
``` cpp
|
| 221 |
basic_istream(basic_istream&& rhs);
|
| 222 |
```
|
| 223 |
|
| 224 |
-
*Effects:*
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
base class, and setting the `gcount()` for `rhs` to 0.
|
| 228 |
|
| 229 |
``` cpp
|
| 230 |
virtual ~basic_istream();
|
| 231 |
```
|
| 232 |
|
| 233 |
-
*Effects:* Destroys an object of class `basic_istream`.
|
| 234 |
-
|
| 235 |
*Remarks:* Does not perform any operations of `rdbuf()`.
|
| 236 |
|
| 237 |
-
#####
|
| 238 |
|
| 239 |
``` cpp
|
| 240 |
basic_istream& operator=(basic_istream&& rhs);
|
| 241 |
```
|
| 242 |
|
| 243 |
-
*Effects:*
|
| 244 |
|
| 245 |
*Returns:* `*this`.
|
| 246 |
|
| 247 |
``` cpp
|
| 248 |
void swap(basic_istream& rhs);
|
| 249 |
```
|
| 250 |
|
| 251 |
*Effects:* Calls `basic_ios<charT, traits>::swap(rhs)`. Exchanges the
|
| 252 |
values returned by `gcount()` and `rhs.gcount()`.
|
| 253 |
|
| 254 |
-
##### Class `basic_istream::sentry` <a id="istream
|
| 255 |
|
| 256 |
``` cpp
|
| 257 |
namespace std {
|
| 258 |
template<class charT, class traits = char_traits<charT>>
|
| 259 |
class basic_istream<charT, traits>::sentry {
|
| 260 |
-
using traits_type = traits;
|
| 261 |
bool ok_; // exposition only
|
| 262 |
public:
|
| 263 |
explicit sentry(basic_istream<charT, traits>& is, bool noskipws = false);
|
| 264 |
~sentry();
|
| 265 |
explicit operator bool() const { return ok_; }
|
|
@@ -310,11 +312,11 @@ if (ctype.is(ctype.space, c) != 0)
|
|
| 310 |
```
|
| 311 |
|
| 312 |
If, after any preparation is completed, `is.good()` is `true`,
|
| 313 |
`ok_ != false` otherwise, `ok_ == false`. During preparation, the
|
| 314 |
constructor may call `setstate(failbit)` (which may throw
|
| 315 |
-
`ios_base::failure`
|
| 316 |
|
| 317 |
``` cpp
|
| 318 |
~sentry();
|
| 319 |
```
|
| 320 |
|
|
@@ -322,23 +324,23 @@ constructor may call `setstate(failbit)` (which may throw
|
|
| 322 |
|
| 323 |
``` cpp
|
| 324 |
explicit operator bool() const;
|
| 325 |
```
|
| 326 |
|
| 327 |
-
*
|
| 328 |
|
| 329 |
#### Formatted input functions <a id="istream.formatted">[[istream.formatted]]</a>
|
| 330 |
|
| 331 |
##### Common requirements <a id="istream.formatted.reqmts">[[istream.formatted.reqmts]]</a>
|
| 332 |
|
| 333 |
Each formatted input function begins execution by constructing an object
|
| 334 |
of class `sentry` with the `noskipws` (second) argument `false`. If the
|
| 335 |
`sentry` object returns `true`, when converted to a value of type
|
| 336 |
`bool`, the function endeavors to obtain the requested input. If an
|
| 337 |
-
exception is thrown during input then `
|
| 338 |
-
`*this`’s error state. If `(exceptions()&badbit) != 0` then
|
| 339 |
-
exception is rethrown. In any case, the formatted input function
|
| 340 |
destroys the `sentry` object. If no exception has been thrown, it
|
| 341 |
returns `*this`.
|
| 342 |
|
| 343 |
##### Arithmetic extractors <a id="istream.formatted.arithmetic">[[istream.formatted.arithmetic]]</a>
|
| 344 |
|
|
@@ -355,11 +357,11 @@ operator>>(long double& val);
|
|
| 355 |
operator>>(bool& val);
|
| 356 |
operator>>(void*& val);
|
| 357 |
```
|
| 358 |
|
| 359 |
As in the case of the inserters, these extractors depend on the locale’s
|
| 360 |
-
`num_get<>`
|
| 361 |
stream data. These extractors behave as formatted input functions (as
|
| 362 |
described in [[istream.formatted.reqmts]]). After a sentry object is
|
| 363 |
constructed, the conversion occurs as if performed by the following code
|
| 364 |
fragment:
|
| 365 |
|
|
@@ -459,26 +461,23 @@ formatted input function (as described
|
|
| 459 |
in [[istream.formatted.reqmts]]).
|
| 460 |
|
| 461 |
*Returns:* `*this`.
|
| 462 |
|
| 463 |
``` cpp
|
| 464 |
-
template<class charT, class traits>
|
| 465 |
-
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& in, charT
|
| 466 |
-
template<class traits>
|
| 467 |
-
basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, unsigned char
|
| 468 |
-
template<class traits>
|
| 469 |
-
basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, signed char
|
| 470 |
```
|
| 471 |
|
| 472 |
*Effects:* Behaves like a formatted input member (as described
|
| 473 |
in [[istream.formatted.reqmts]]) of `in`. After a `sentry` object is
|
| 474 |
-
constructed, `operator>>` extracts characters and stores them into
|
| 475 |
-
|
| 476 |
-
`
|
| 477 |
-
is the number of elements of the largest array of `char_type` that can
|
| 478 |
-
store a terminating `charT()`. `n` is the maximum number of characters
|
| 479 |
-
stored.
|
| 480 |
|
| 481 |
Characters are extracted and stored until any of the following occurs:
|
| 482 |
|
| 483 |
- `n-1` characters are stored;
|
| 484 |
- end of file occurs on the input sequence;
|
|
@@ -488,11 +487,11 @@ Characters are extracted and stored until any of the following occurs:
|
|
| 488 |
`operator>>` then stores a null byte (`charT()`) in the next position,
|
| 489 |
which may be the first position if no characters were extracted.
|
| 490 |
`operator>>` then calls `width(0)`.
|
| 491 |
|
| 492 |
If the function extracted no characters, it calls `setstate(failbit)`,
|
| 493 |
-
which may throw `ios_base::failure`
|
| 494 |
|
| 495 |
*Returns:* `in`.
|
| 496 |
|
| 497 |
``` cpp
|
| 498 |
template<class charT, class traits>
|
|
@@ -512,28 +511,28 @@ stored in `c`. Otherwise, the function calls `in.setstate(failbit)`.
|
|
| 512 |
|
| 513 |
``` cpp
|
| 514 |
basic_istream<charT, traits>& operator>>(basic_streambuf<charT, traits>* sb);
|
| 515 |
```
|
| 516 |
|
| 517 |
-
*Effects:* Behaves as an unformatted input
|
| 518 |
-
|
| 519 |
-
which may throw `ios_base::failure`
|
| 520 |
-
object is constructed, extracts
|
| 521 |
-
|
| 522 |
-
inserted until any of
|
|
|
|
| 523 |
|
| 524 |
- end-of-file occurs on the input sequence;
|
| 525 |
- inserting in the output sequence fails (in which case the character to
|
| 526 |
be inserted is not extracted);
|
| 527 |
- an exception occurs (in which case the exception is caught).
|
| 528 |
|
| 529 |
If the function inserts no characters, it calls `setstate(failbit)`,
|
| 530 |
-
which may throw `ios_base::failure`
|
| 531 |
-
|
| 532 |
-
characters from `*this` and `failbit` is
|
| 533 |
-
|
| 534 |
-
rethrown.
|
| 535 |
|
| 536 |
*Returns:* `*this`.
|
| 537 |
|
| 538 |
#### Unformatted input functions <a id="istream.unformatted">[[istream.unformatted]]</a>
|
| 539 |
|
|
@@ -546,14 +545,14 @@ an exception or if the sentry object returns `false`, when converted to
|
|
| 546 |
a value of type `bool`, the function returns without attempting to
|
| 547 |
obtain any input. In either case the number of extracted characters is
|
| 548 |
set to 0; unformatted input functions taking a character array of
|
| 549 |
nonzero size as an argument shall also store a null character (using
|
| 550 |
`charT()`) in the first location of the array. If an exception is thrown
|
| 551 |
-
during input then `
|
| 552 |
-
state. (Exceptions thrown from `basic_ios<>::clear()` are not
|
| 553 |
-
rethrown.) If `(exceptions()&badbit) != 0` then the exception
|
| 554 |
-
rethrown. It also counts the number of characters extracted. If no
|
| 555 |
exception has been thrown it ends by storing the count in a member
|
| 556 |
object and returning the value specified. In any event the `sentry`
|
| 557 |
object is destroyed before leaving the unformatted input function.
|
| 558 |
|
| 559 |
``` cpp
|
|
@@ -571,23 +570,23 @@ int_type get();
|
|
| 571 |
```
|
| 572 |
|
| 573 |
*Effects:* Behaves as an unformatted input function (as described
|
| 574 |
above). After constructing a sentry object, extracts a character `c`, if
|
| 575 |
one is available. Otherwise, the function calls `setstate(failbit)`,
|
| 576 |
-
which may throw `ios_base::failure`
|
| 577 |
|
| 578 |
*Returns:* `c` if available, otherwise `traits::eof()`.
|
| 579 |
|
| 580 |
``` cpp
|
| 581 |
basic_istream<charT, traits>& get(char_type& c);
|
| 582 |
```
|
| 583 |
|
| 584 |
*Effects:* Behaves as an unformatted input function (as described
|
| 585 |
above). After constructing a sentry object, extracts a character, if one
|
| 586 |
is available, and assigns it to `c`.[^24] Otherwise, the function calls
|
| 587 |
-
`setstate(failbit)` (which may throw
|
| 588 |
-
|
| 589 |
|
| 590 |
*Returns:* `*this`.
|
| 591 |
|
| 592 |
``` cpp
|
| 593 |
basic_istream<charT, traits>& get(char_type* s, streamsize n, char_type delim);
|
|
@@ -604,13 +603,13 @@ the following occurs:
|
|
| 604 |
calls `setstate(eofbit)`);
|
| 605 |
- `traits::eq(c, delim)` for the next available input character `c` (in
|
| 606 |
which case `c` is not extracted).
|
| 607 |
|
| 608 |
If the function stores no characters, it calls `setstate(failbit)`
|
| 609 |
-
(which may throw `ios_base::failure`
|
| 610 |
-
|
| 611 |
-
|
| 612 |
|
| 613 |
*Returns:* `*this`.
|
| 614 |
|
| 615 |
``` cpp
|
| 616 |
basic_istream<charT, traits>& get(char_type* s, streamsize n);
|
|
@@ -636,11 +635,11 @@ extracted and inserted until any of the following occurs:
|
|
| 636 |
which case `c` is not extracted);
|
| 637 |
- an exception occurs (in which case, the exception is caught but not
|
| 638 |
rethrown).
|
| 639 |
|
| 640 |
If the function inserts no characters, it calls `setstate(failbit)`,
|
| 641 |
-
which may throw `ios_base::failure`
|
| 642 |
|
| 643 |
*Returns:* `*this`.
|
| 644 |
|
| 645 |
``` cpp
|
| 646 |
basic_istream<charT, traits>& get(basic_streambuf<char_type, traits>& sb);
|
|
@@ -669,11 +668,11 @@ the following occurs:
|
|
| 669 |
the function calls `setstate(failbit)`).
|
| 670 |
|
| 671 |
These conditions are tested in the order shown.[^28]
|
| 672 |
|
| 673 |
If the function extracts no characters, it calls `setstate(failbit)`
|
| 674 |
-
(which may throw `ios_base::failure`
|
| 675 |
|
| 676 |
In any case, if `n` is greater than zero, it then stores a null
|
| 677 |
character (using `charT()`) into the next successive location of the
|
| 678 |
array.
|
| 679 |
|
|
@@ -721,15 +720,15 @@ basic_istream<charT, traits>& ignore(streamsize n = 1, int_type delim = traits::
|
|
| 721 |
*Effects:* Behaves as an unformatted input function (as described
|
| 722 |
above). After constructing a sentry object, extracts characters and
|
| 723 |
discards them. Characters are extracted until any of the following
|
| 724 |
occurs:
|
| 725 |
|
| 726 |
-
- `n != numeric_limits<streamsize>::max()`
|
| 727 |
characters have been extracted so far
|
| 728 |
- end-of-file occurs on the input sequence (in which case the function
|
| 729 |
-
calls `setstate(eofbit)`, which may throw
|
| 730 |
-
|
| 731 |
- `traits::eq_int_type(traits::to_int_type(c), delim)` for the next
|
| 732 |
available input character `c` (in which case `c` is extracted).
|
| 733 |
|
| 734 |
*Remarks:* The last condition will never occur if
|
| 735 |
`traits::eq_int_type(delim, traits::eof())`.
|
|
@@ -759,11 +758,11 @@ array whose first element is designated by `s`.[^30] Characters are
|
|
| 759 |
extracted and stored until either of the following occurs:
|
| 760 |
|
| 761 |
- `n` characters are stored;
|
| 762 |
- end-of-file occurs on the input sequence (in which case the function
|
| 763 |
calls `setstate(failbit | eofbit)`, which may throw
|
| 764 |
-
`ios_base::failure`
|
| 765 |
|
| 766 |
*Returns:* `*this`.
|
| 767 |
|
| 768 |
``` cpp
|
| 769 |
streamsize readsome(char_type* s, streamsize n);
|
|
@@ -773,11 +772,11 @@ streamsize readsome(char_type* s, streamsize n);
|
|
| 773 |
above). After constructing a sentry object, if `!good()` calls
|
| 774 |
`setstate(failbit)` which may throw an exception, and return. Otherwise
|
| 775 |
extracts characters and stores them into successive locations of an
|
| 776 |
array whose first element is designated by `s`. If
|
| 777 |
`rdbuf()->in_avail() == -1`, calls `setstate(eofbit)` (which may throw
|
| 778 |
-
`ios_base::failure`
|
| 779 |
|
| 780 |
- If `rdbuf()->in_avail() == 0`, extracts no characters
|
| 781 |
- If `rdbuf()->in_avail() > 0`, extracts `min(rdbuf()->in_avail(), n))`.
|
| 782 |
|
| 783 |
*Returns:* The number of characters extracted.
|
|
@@ -788,13 +787,13 @@ basic_istream<charT, traits>& putback(char_type c);
|
|
| 788 |
|
| 789 |
*Effects:* Behaves as an unformatted input function (as described
|
| 790 |
above), except that the function first clears `eofbit`. After
|
| 791 |
constructing a sentry object, if `!good()` calls `setstate(failbit)`
|
| 792 |
which may throw an exception, and return. If `rdbuf()` is not null,
|
| 793 |
-
calls `rdbuf->sputbackc()`. If `rdbuf()` is null, or if `sputbackc
|
| 794 |
returns `traits::eof()`, calls `setstate(badbit)` (which may throw
|
| 795 |
-
`ios_base::failure`
|
| 796 |
|
| 797 |
[*Note 1*: This function extracts no characters, so the value returned
|
| 798 |
by the next call to `gcount()` is 0. — *end note*]
|
| 799 |
|
| 800 |
*Returns:* `*this`.
|
|
@@ -805,13 +804,13 @@ basic_istream<charT, traits>& unget();
|
|
| 805 |
|
| 806 |
*Effects:* Behaves as an unformatted input function (as described
|
| 807 |
above), except that the function first clears `eofbit`. After
|
| 808 |
constructing a sentry object, if `!good()` calls `setstate(failbit)`
|
| 809 |
which may throw an exception, and return. If `rdbuf()` is not null,
|
| 810 |
-
calls `rdbuf()->sungetc()`. If `rdbuf()` is null, or if `sungetc
|
| 811 |
returns `traits::eof()`, calls `setstate(badbit)` (which may throw
|
| 812 |
-
`ios_base::failure`
|
| 813 |
|
| 814 |
[*Note 2*: This function extracts no characters, so the value returned
|
| 815 |
by the next call to `gcount()` is 0. — *end note*]
|
| 816 |
|
| 817 |
*Returns:* `*this`.
|
|
@@ -824,11 +823,11 @@ int sync();
|
|
| 824 |
above), except that it does not count the number of characters extracted
|
| 825 |
and does not affect the value returned by subsequent calls to
|
| 826 |
`gcount()`. After constructing a sentry object, if `rdbuf()` is a null
|
| 827 |
pointer, returns `-1`. Otherwise, calls `rdbuf()->pubsync()` and, if
|
| 828 |
that function returns `-1` calls `setstate(badbit)` (which may throw
|
| 829 |
-
`ios_base::failure`
|
| 830 |
returns zero.
|
| 831 |
|
| 832 |
``` cpp
|
| 833 |
pos_type tellg();
|
| 834 |
```
|
|
@@ -872,45 +871,49 @@ function calls `setstate(failbit)` (which may throw
|
|
| 872 |
|
| 873 |
*Returns:* `*this`.
|
| 874 |
|
| 875 |
#### Standard `basic_istream` manipulators <a id="istream.manip">[[istream.manip]]</a>
|
| 876 |
|
|
|
|
|
|
|
|
|
|
| 877 |
``` cpp
|
| 878 |
template<class charT, class traits>
|
| 879 |
basic_istream<charT, traits>& ws(basic_istream<charT, traits>& is);
|
| 880 |
```
|
| 881 |
|
| 882 |
-
*Effects:* Behaves as an unformatted input
|
| 883 |
-
|
| 884 |
-
characters extracted and does not affect the value returned by
|
| 885 |
-
subsequent calls to is.gcount(). After constructing a sentry object
|
| 886 |
extracts characters as long as the next available character `c` is
|
| 887 |
whitespace or until there are no more characters in the sequence.
|
| 888 |
Whitespace characters are distinguished with the same criterion as used
|
| 889 |
-
by `sentry::sentry`
|
| 890 |
characters because there are no more available it sets `eofbit`, but not
|
| 891 |
`failbit`.
|
| 892 |
|
| 893 |
*Returns:* `is`.
|
| 894 |
|
| 895 |
#### Rvalue stream extraction <a id="istream.rvalue">[[istream.rvalue]]</a>
|
| 896 |
|
| 897 |
``` cpp
|
| 898 |
-
template
|
| 899 |
-
|
| 900 |
```
|
| 901 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 902 |
*Effects:* Equivalent to:
|
| 903 |
|
| 904 |
``` cpp
|
| 905 |
is >> std::forward<T>(x);
|
| 906 |
-
return is;
|
| 907 |
```
|
| 908 |
|
| 909 |
-
*Remarks:* This function shall not participate in overload resolution
|
| 910 |
-
unless the expression `is >> std::forward<T>(x)` is well-formed.
|
| 911 |
-
|
| 912 |
#### Class template `basic_iostream` <a id="iostreamclass">[[iostreamclass]]</a>
|
| 913 |
|
| 914 |
``` cpp
|
| 915 |
namespace std {
|
| 916 |
template<class charT, class traits = char_traits<charT>>
|
|
@@ -930,62 +933,59 @@ namespace std {
|
|
| 930 |
// [iostream.dest], destructor
|
| 931 |
virtual ~basic_iostream();
|
| 932 |
|
| 933 |
protected:
|
| 934 |
// [iostream.cons], constructor
|
| 935 |
-
basic_iostream(const basic_iostream&
|
| 936 |
basic_iostream(basic_iostream&& rhs);
|
| 937 |
|
| 938 |
// [iostream.assign], assign and swap
|
| 939 |
-
basic_iostream& operator=(const basic_iostream&
|
| 940 |
basic_iostream& operator=(basic_iostream&& rhs);
|
| 941 |
void swap(basic_iostream& rhs);
|
| 942 |
};
|
| 943 |
}
|
| 944 |
```
|
| 945 |
|
| 946 |
The class template `basic_iostream` inherits a number of functions that
|
| 947 |
allow reading input and writing output to sequences controlled by a
|
| 948 |
stream buffer.
|
| 949 |
|
| 950 |
-
#####
|
| 951 |
|
| 952 |
``` cpp
|
| 953 |
explicit basic_iostream(basic_streambuf<charT, traits>* sb);
|
| 954 |
```
|
| 955 |
|
| 956 |
-
*Effects:*
|
| 957 |
-
|
| 958 |
-
`
|
| 959 |
-
`basic_ostream<charT, traits>(sb)` ([[ostream]]).
|
| 960 |
|
| 961 |
-
*
|
| 962 |
|
| 963 |
``` cpp
|
| 964 |
basic_iostream(basic_iostream&& rhs);
|
| 965 |
```
|
| 966 |
|
| 967 |
*Effects:* Move constructs from the rvalue `rhs` by constructing the
|
| 968 |
`basic_istream` base class with `move(rhs)`.
|
| 969 |
|
| 970 |
-
#####
|
| 971 |
|
| 972 |
``` cpp
|
| 973 |
virtual ~basic_iostream();
|
| 974 |
```
|
| 975 |
|
| 976 |
-
*Effects:* Destroys an object of class `basic_iostream`.
|
| 977 |
-
|
| 978 |
*Remarks:* Does not perform any operations on `rdbuf()`.
|
| 979 |
|
| 980 |
-
#####
|
| 981 |
|
| 982 |
``` cpp
|
| 983 |
basic_iostream& operator=(basic_iostream&& rhs);
|
| 984 |
```
|
| 985 |
|
| 986 |
-
*Effects:*
|
| 987 |
|
| 988 |
``` cpp
|
| 989 |
void swap(basic_iostream& rhs);
|
| 990 |
```
|
| 991 |
|
|
@@ -1002,22 +1002,22 @@ that inserts into stream rvalues.
|
|
| 1002 |
``` cpp
|
| 1003 |
namespace std {
|
| 1004 |
template<class charT, class traits = char_traits<charT>>
|
| 1005 |
class basic_ostream : virtual public basic_ios<charT, traits> {
|
| 1006 |
public:
|
| 1007 |
-
// types (inherited from basic_ios
|
| 1008 |
using char_type = charT;
|
| 1009 |
using int_type = typename traits::int_type;
|
| 1010 |
using pos_type = typename traits::pos_type;
|
| 1011 |
using off_type = typename traits::off_type;
|
| 1012 |
using traits_type = traits;
|
| 1013 |
|
| 1014 |
// [ostream.cons], constructor/destructor
|
| 1015 |
explicit basic_ostream(basic_streambuf<char_type, traits>* sb);
|
| 1016 |
virtual ~basic_ostream();
|
| 1017 |
|
| 1018 |
-
// [ostream
|
| 1019 |
class sentry;
|
| 1020 |
|
| 1021 |
// [ostream.formatted], formatted output
|
| 1022 |
basic_ostream<charT, traits>&
|
| 1023 |
operator<<(basic_ostream<charT, traits>& (*pf)(basic_ostream<charT, traits>&));
|
|
@@ -1054,15 +1054,15 @@ namespace std {
|
|
| 1054 |
basic_ostream<charT, traits>& seekp(pos_type);
|
| 1055 |
basic_ostream<charT, traits>& seekp(off_type, ios_base::seekdir);
|
| 1056 |
|
| 1057 |
protected:
|
| 1058 |
// [ostream.cons], copy/move constructor
|
| 1059 |
-
basic_ostream(const basic_ostream&
|
| 1060 |
basic_ostream(basic_ostream&& rhs);
|
| 1061 |
|
| 1062 |
// [ostream.assign], assign and swap
|
| 1063 |
-
basic_ostream& operator=(const basic_ostream&
|
| 1064 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 1065 |
void swap(basic_ostream& rhs);
|
| 1066 |
};
|
| 1067 |
|
| 1068 |
// [ostream.inserters.character], character inserters
|
|
@@ -1076,10 +1076,28 @@ namespace std {
|
|
| 1076 |
template<class traits>
|
| 1077 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, signed char);
|
| 1078 |
template<class traits>
|
| 1079 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, unsigned char);
|
| 1080 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1081 |
template<class charT, class traits>
|
| 1082 |
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const charT*);
|
| 1083 |
template<class charT, class traits>
|
| 1084 |
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const char*);
|
| 1085 |
template<class traits>
|
|
@@ -1087,10 +1105,32 @@ namespace std {
|
|
| 1087 |
|
| 1088 |
template<class traits>
|
| 1089 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const signed char*);
|
| 1090 |
template<class traits>
|
| 1091 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const unsigned char*);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1092 |
}
|
| 1093 |
```
|
| 1094 |
|
| 1095 |
The class template `basic_ostream` defines a number of member function
|
| 1096 |
signatures that assist in formatting and writing output to output
|
|
@@ -1103,26 +1143,29 @@ output functions.* Both groups of output functions generate (or
|
|
| 1103 |
`rdbuf()->sputc(int_type)`. They may use other public members of
|
| 1104 |
`basic_ostream` except that they shall not invoke any virtual members of
|
| 1105 |
`rdbuf()` except `overflow()`, `xsputn()`, and `sync()`.
|
| 1106 |
|
| 1107 |
If one of these called functions throws an exception, then unless
|
| 1108 |
-
explicitly noted otherwise the output function sets `badbit` in
|
| 1109 |
-
state. If `badbit` is
|
| 1110 |
-
the exception without completing its actions, otherwise it does
|
| 1111 |
-
throw anything and
|
|
|
|
| 1112 |
|
| 1113 |
-
|
|
|
|
|
|
|
|
|
|
| 1114 |
|
| 1115 |
``` cpp
|
| 1116 |
explicit basic_ostream(basic_streambuf<charT, traits>* sb);
|
| 1117 |
```
|
| 1118 |
|
| 1119 |
-
*Effects:*
|
| 1120 |
-
|
| 1121 |
-
`basic_ios<charT, traits>::init(sb)` ([[basic.ios.cons]]).
|
| 1122 |
|
| 1123 |
-
*
|
| 1124 |
|
| 1125 |
``` cpp
|
| 1126 |
basic_ostream(basic_ostream&& rhs);
|
| 1127 |
```
|
| 1128 |
|
|
@@ -1132,31 +1175,29 @@ by default constructing the base class and calling
|
|
| 1132 |
|
| 1133 |
``` cpp
|
| 1134 |
virtual ~basic_ostream();
|
| 1135 |
```
|
| 1136 |
|
| 1137 |
-
*Effects:* Destroys an object of class `basic_ostream`.
|
| 1138 |
-
|
| 1139 |
*Remarks:* Does not perform any operations on `rdbuf()`.
|
| 1140 |
|
| 1141 |
-
#####
|
| 1142 |
|
| 1143 |
``` cpp
|
| 1144 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 1145 |
```
|
| 1146 |
|
| 1147 |
-
*Effects:*
|
| 1148 |
|
| 1149 |
*Returns:* `*this`.
|
| 1150 |
|
| 1151 |
``` cpp
|
| 1152 |
void swap(basic_ostream& rhs);
|
| 1153 |
```
|
| 1154 |
|
| 1155 |
*Effects:* Calls `basic_ios<charT, traits>::swap(rhs)`.
|
| 1156 |
|
| 1157 |
-
##### Class `basic_ostream::sentry` <a id="ostream
|
| 1158 |
|
| 1159 |
``` cpp
|
| 1160 |
namespace std {
|
| 1161 |
template<class charT, class traits = char_traits<charT>>
|
| 1162 |
class basic_ostream<charT, traits>::sentry {
|
|
@@ -1183,11 +1224,11 @@ If `os.good()` is nonzero, prepares for formatted or unformatted output.
|
|
| 1183 |
If `os.tie()` is not a null pointer, calls `os.tie()->flush()`.[^31]
|
| 1184 |
|
| 1185 |
If, after any preparation is completed, `os.good()` is `true`,
|
| 1186 |
`ok_ == true` otherwise, `ok_ == false`. During preparation, the
|
| 1187 |
constructor may call `setstate(failbit)` (which may throw
|
| 1188 |
-
`ios_base::failure`
|
| 1189 |
|
| 1190 |
``` cpp
|
| 1191 |
~sentry();
|
| 1192 |
```
|
| 1193 |
|
|
@@ -1200,11 +1241,11 @@ sets `badbit` in `os.rdstate()` without propagating an exception.
|
|
| 1200 |
explicit operator bool() const;
|
| 1201 |
```
|
| 1202 |
|
| 1203 |
*Effects:* Returns `ok_`.
|
| 1204 |
|
| 1205 |
-
#####
|
| 1206 |
|
| 1207 |
Each seek member function begins execution by constructing an object of
|
| 1208 |
class `sentry`. It returns by destroying the `sentry` object.
|
| 1209 |
|
| 1210 |
``` cpp
|
|
@@ -1243,12 +1284,12 @@ function calls `setstate(failbit)` (which may throw
|
|
| 1243 |
Each formatted output function begins execution by constructing an
|
| 1244 |
object of class `sentry`. If this object returns `true` when converted
|
| 1245 |
to a value of type `bool`, the function endeavors to generate the
|
| 1246 |
requested output. If the generation fails, then the formatted output
|
| 1247 |
function does `setstate(ios_base::failbit)`, which might throw an
|
| 1248 |
-
exception. If an exception is thrown during output, then
|
| 1249 |
-
is turned on[^33] in `*this`’s error state. If
|
| 1250 |
`(exceptions()&badbit) != 0` then the exception is rethrown. Whether or
|
| 1251 |
not an exception is thrown, the `sentry` object is destroyed before
|
| 1252 |
leaving the formatted output function. If no exception is thrown, the
|
| 1253 |
result of the formatted output function is `*this`.
|
| 1254 |
|
|
@@ -1389,13 +1430,13 @@ in [[ostream.formatted.reqmts]]).
|
|
| 1389 |
|
| 1390 |
``` cpp
|
| 1391 |
basic_ostream<charT, traits>& operator<<(basic_streambuf<charT, traits>* sb);
|
| 1392 |
```
|
| 1393 |
|
| 1394 |
-
*Effects:* Behaves as an unformatted output
|
| 1395 |
-
|
| 1396 |
-
`sb` is null calls `setstate(badbit)` (which may throw
|
| 1397 |
`ios_base::failure`).
|
| 1398 |
|
| 1399 |
Gets characters from `sb` and inserts them in `*this`. Characters are
|
| 1400 |
read from `sb` and inserted until any of the following occurs:
|
| 1401 |
|
|
@@ -1403,14 +1444,14 @@ read from `sb` and inserted until any of the following occurs:
|
|
| 1403 |
- inserting in the output sequence fails (in which case the character to
|
| 1404 |
be inserted is not extracted);
|
| 1405 |
- an exception occurs while getting a character from `sb`.
|
| 1406 |
|
| 1407 |
If the function inserts no characters, it calls `setstate(failbit)`
|
| 1408 |
-
(which may throw `ios_base::failure`
|
| 1409 |
-
|
| 1410 |
-
|
| 1411 |
-
|
| 1412 |
|
| 1413 |
*Returns:* `*this`.
|
| 1414 |
|
| 1415 |
``` cpp
|
| 1416 |
basic_ostream<charT, traits>& operator<<(nullptr_t);
|
|
@@ -1420,11 +1461,11 @@ basic_ostream<charT, traits>& operator<<(nullptr_t);
|
|
| 1420 |
|
| 1421 |
``` cpp
|
| 1422 |
return *this << s;
|
| 1423 |
```
|
| 1424 |
|
| 1425 |
-
where `s` is an *implementation-defined* NTCTS
|
| 1426 |
|
| 1427 |
##### Character inserter function templates <a id="ostream.inserters.character">[[ostream.inserters.character]]</a>
|
| 1428 |
|
| 1429 |
``` cpp
|
| 1430 |
template<class charT, class traits>
|
|
@@ -1440,16 +1481,16 @@ template<class traits>
|
|
| 1440 |
template<class traits>
|
| 1441 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, unsigned char c);
|
| 1442 |
```
|
| 1443 |
|
| 1444 |
*Effects:* Behaves as a formatted output
|
| 1445 |
-
function
|
| 1446 |
-
|
| 1447 |
-
|
| 1448 |
-
|
| 1449 |
-
|
| 1450 |
-
|
| 1451 |
|
| 1452 |
*Returns:* `out`.
|
| 1453 |
|
| 1454 |
``` cpp
|
| 1455 |
template<class charT, class traits>
|
|
@@ -1463,17 +1504,17 @@ template<class traits>
|
|
| 1463 |
template<class traits>
|
| 1464 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out,
|
| 1465 |
const unsigned char* s);
|
| 1466 |
```
|
| 1467 |
|
| 1468 |
-
*
|
| 1469 |
|
| 1470 |
*Effects:* Behaves like a formatted inserter (as described
|
| 1471 |
in [[ostream.formatted.reqmts]]) of `out`. Creates a character sequence
|
| 1472 |
`seq` of `n` characters starting at `s`, each widened using
|
| 1473 |
-
`out.widen()`
|
| 1474 |
-
|
| 1475 |
|
| 1476 |
- `traits::length(s)` for the overload where the first argument is of
|
| 1477 |
type `basic_ostream<charT, traits>&` and the second is of type
|
| 1478 |
`const charT*`, and also for the overload where the first argument is
|
| 1479 |
of type `basic_ostream<char, traits>&` and the second is of type
|
|
@@ -1494,11 +1535,11 @@ in [[ostream.formatted.reqmts]]. Inserts `seq` into `out`. Calls
|
|
| 1494 |
|
| 1495 |
Each unformatted output function begins execution by constructing an
|
| 1496 |
object of class `sentry`. If this object returns `true`, while
|
| 1497 |
converting to a value of type `bool`, the function endeavors to generate
|
| 1498 |
the requested output. If an exception is thrown during output, then
|
| 1499 |
-
`
|
| 1500 |
`(exceptions() & badbit) != 0` then the exception is rethrown. In any
|
| 1501 |
case, the unformatted output function ends by destroying the sentry
|
| 1502 |
object, then, if no exception was thrown, returning the value specified
|
| 1503 |
for the unformatted output function.
|
| 1504 |
|
|
@@ -1508,12 +1549,12 @@ basic_ostream<charT, traits>& put(char_type c);
|
|
| 1508 |
|
| 1509 |
*Effects:* Behaves as an unformatted output function (as described
|
| 1510 |
above). After constructing a sentry object, inserts the character `c`,
|
| 1511 |
if possible.[^37]
|
| 1512 |
|
| 1513 |
-
Otherwise, calls `setstate(badbit)` (which may throw
|
| 1514 |
-
|
| 1515 |
|
| 1516 |
*Returns:* `*this`.
|
| 1517 |
|
| 1518 |
``` cpp
|
| 1519 |
basic_ostream& write(const char_type* s, streamsize n);
|
|
@@ -1525,12 +1566,12 @@ from successive locations of an array whose first element is designated
|
|
| 1525 |
by `s`.[^38] Characters are inserted until either of the following
|
| 1526 |
occurs:
|
| 1527 |
|
| 1528 |
- `n` characters are inserted;
|
| 1529 |
- inserting in the output sequence fails (in which case the function
|
| 1530 |
-
calls `setstate(badbit)`, which may throw
|
| 1531 |
-
|
| 1532 |
|
| 1533 |
*Returns:* `*this`.
|
| 1534 |
|
| 1535 |
``` cpp
|
| 1536 |
basic_ostream& flush();
|
|
@@ -1538,17 +1579,20 @@ basic_ostream& flush();
|
|
| 1538 |
|
| 1539 |
*Effects:* Behaves as an unformatted output function (as described
|
| 1540 |
above). If `rdbuf()` is not a null pointer, constructs a sentry object.
|
| 1541 |
If this object returns `true` when converted to a value of type `bool`
|
| 1542 |
the function calls `rdbuf()->pubsync()`. If that function returns -1
|
| 1543 |
-
calls `setstate(badbit)` (which may throw
|
| 1544 |
-
|
| 1545 |
-
|
| 1546 |
|
| 1547 |
*Returns:* `*this`.
|
| 1548 |
|
| 1549 |
-
#### Standard
|
|
|
|
|
|
|
|
|
|
| 1550 |
|
| 1551 |
``` cpp
|
| 1552 |
template<class charT, class traits>
|
| 1553 |
basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);
|
| 1554 |
```
|
|
@@ -1574,23 +1618,64 @@ template <class charT, class traits>
|
|
| 1574 |
|
| 1575 |
*Effects:* Calls `os.flush()`.
|
| 1576 |
|
| 1577 |
*Returns:* `os`.
|
| 1578 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1579 |
#### Rvalue stream insertion <a id="ostream.rvalue">[[ostream.rvalue]]</a>
|
| 1580 |
|
| 1581 |
``` cpp
|
| 1582 |
-
template
|
| 1583 |
-
|
| 1584 |
```
|
| 1585 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1586 |
*Effects:* As if by: `os << x;`
|
| 1587 |
|
| 1588 |
-
*Returns:* `os`.
|
| 1589 |
-
|
| 1590 |
-
*Remarks:* This function shall not participate in overload resolution
|
| 1591 |
-
unless the expression `os << x` is well-formed.
|
| 1592 |
|
| 1593 |
### Standard manipulators <a id="std.manip">[[std.manip]]</a>
|
| 1594 |
|
| 1595 |
The header `<iomanip>` defines several functions that support extractors
|
| 1596 |
and inserters that alter information maintained by class `ios_base` and
|
|
@@ -1612,14 +1697,14 @@ void f(ios_base& str, ios_base::fmtflags mask) {
|
|
| 1612 |
// reset specified flags
|
| 1613 |
str.setf(ios_base::fmtflags(0), mask);
|
| 1614 |
}
|
| 1615 |
```
|
| 1616 |
|
| 1617 |
-
The expression `out << resetiosflags(mask)`
|
| 1618 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1619 |
-
`in >> resetiosflags(mask)`
|
| 1620 |
-
|
| 1621 |
|
| 1622 |
``` cpp
|
| 1623 |
unspecified setiosflags(ios_base::fmtflags mask);
|
| 1624 |
```
|
| 1625 |
|
|
@@ -1635,14 +1720,14 @@ void f(ios_base& str, ios_base::fmtflags mask) {
|
|
| 1635 |
// set specified flags
|
| 1636 |
str.setf(mask);
|
| 1637 |
}
|
| 1638 |
```
|
| 1639 |
|
| 1640 |
-
The expression `out << setiosflags(mask)`
|
| 1641 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1642 |
-
`in >> setiosflags(mask)`
|
| 1643 |
-
|
| 1644 |
|
| 1645 |
``` cpp
|
| 1646 |
unspecified setbase(int base);
|
| 1647 |
```
|
| 1648 |
|
|
@@ -1661,14 +1746,14 @@ void f(ios_base& str, int base) {
|
|
| 1661 |
base == 16 ? ios_base::hex :
|
| 1662 |
ios_base::fmtflags(0), ios_base::basefield);
|
| 1663 |
}
|
| 1664 |
```
|
| 1665 |
|
| 1666 |
-
The expression `out << setbase(base)`
|
| 1667 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1668 |
-
`in >> setbase(base)`
|
| 1669 |
-
|
| 1670 |
|
| 1671 |
``` cpp
|
| 1672 |
unspecified setfill(char_type c);
|
| 1673 |
```
|
| 1674 |
|
|
@@ -1683,11 +1768,11 @@ void f(basic_ios<charT, traits>& str, charT c) {
|
|
| 1683 |
// set fill character
|
| 1684 |
str.fill(c);
|
| 1685 |
}
|
| 1686 |
```
|
| 1687 |
|
| 1688 |
-
The expression `out << setfill(c)`
|
| 1689 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1690 |
|
| 1691 |
``` cpp
|
| 1692 |
unspecified setprecision(int n);
|
| 1693 |
```
|
|
@@ -1704,14 +1789,14 @@ void f(ios_base& str, int n) {
|
|
| 1704 |
// set precision
|
| 1705 |
str.precision(n);
|
| 1706 |
}
|
| 1707 |
```
|
| 1708 |
|
| 1709 |
-
The expression `out << setprecision(n)`
|
| 1710 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1711 |
-
`in >> setprecision(n)`
|
| 1712 |
-
|
| 1713 |
|
| 1714 |
``` cpp
|
| 1715 |
unspecified setw(int n);
|
| 1716 |
```
|
| 1717 |
|
|
@@ -1727,14 +1812,13 @@ void f(ios_base& str, int n) {
|
|
| 1727 |
// set width
|
| 1728 |
str.width(n);
|
| 1729 |
}
|
| 1730 |
```
|
| 1731 |
|
| 1732 |
-
The expression `out << setw(n)`
|
| 1733 |
-
|
| 1734 |
-
`
|
| 1735 |
-
value `in`.
|
| 1736 |
|
| 1737 |
### Extended manipulators <a id="ext.manip">[[ext.manip]]</a>
|
| 1738 |
|
| 1739 |
The header `<iomanip>` defines several functions that support extractors
|
| 1740 |
and inserters that allow for the parsing and formatting of sequences and
|
|
@@ -1742,15 +1826,15 @@ values for money and time.
|
|
| 1742 |
|
| 1743 |
``` cpp
|
| 1744 |
template<class moneyT> unspecified get_money(moneyT& mon, bool intl = false);
|
| 1745 |
```
|
| 1746 |
|
| 1747 |
-
*
|
| 1748 |
-
specialization of the `basic_string` template
|
| 1749 |
|
| 1750 |
*Effects:* The expression `in >> get_money(mon, intl)` described below
|
| 1751 |
-
behaves as a formatted input function
|
| 1752 |
|
| 1753 |
*Returns:* An object of unspecified type such that if `in` is an object
|
| 1754 |
of type `basic_istream<charT, traits>` then the expression
|
| 1755 |
`in >> get_money(mon, intl)` behaves as if it called `f(in, mon, intl)`,
|
| 1756 |
where the function `f` is defined as:
|
|
@@ -1769,24 +1853,24 @@ void f(basic_ios<charT, traits>& str, moneyT& mon, bool intl) {
|
|
| 1769 |
if (ios_base::goodbit != err)
|
| 1770 |
str.setstate(err);
|
| 1771 |
}
|
| 1772 |
```
|
| 1773 |
|
| 1774 |
-
The expression `in >> get_money(mon, intl)`
|
| 1775 |
`basic_istream<charT, traits>&` and value `in`.
|
| 1776 |
|
| 1777 |
``` cpp
|
| 1778 |
template<class moneyT> unspecified put_money(const moneyT& mon, bool intl = false);
|
| 1779 |
```
|
| 1780 |
|
| 1781 |
-
*
|
| 1782 |
-
specialization of the `basic_string` template
|
| 1783 |
|
| 1784 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1785 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1786 |
`out << put_money(mon, intl)` behaves as a formatted output
|
| 1787 |
-
function
|
| 1788 |
where the function `f` is defined as:
|
| 1789 |
|
| 1790 |
``` cpp
|
| 1791 |
template<class charT, class traits, class moneyT>
|
| 1792 |
void f(basic_ios<charT, traits>& str, const moneyT& mon, bool intl) {
|
|
@@ -1795,25 +1879,24 @@ void f(basic_ios<charT, traits>& str, const moneyT& mon, bool intl) {
|
|
| 1795 |
|
| 1796 |
const MoneyPut& mp = use_facet<MoneyPut>(str.getloc());
|
| 1797 |
const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon);
|
| 1798 |
|
| 1799 |
if (end.failed())
|
| 1800 |
-
str.setstate(
|
| 1801 |
}
|
| 1802 |
```
|
| 1803 |
|
| 1804 |
-
The expression `out << put_money(mon, intl)`
|
| 1805 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1806 |
|
| 1807 |
``` cpp
|
| 1808 |
template<class charT> unspecified get_time(struct tm* tmb, const charT* fmt);
|
| 1809 |
```
|
| 1810 |
|
| 1811 |
-
*
|
| 1812 |
-
type `struct tm`
|
| 1813 |
-
|
| 1814 |
-
elements.
|
| 1815 |
|
| 1816 |
*Returns:* An object of unspecified type such that if `in` is an object
|
| 1817 |
of type `basic_istream<charT, traits>` then the expression
|
| 1818 |
`in >> get_time(tmb, fmt)` behaves as if it called `f(in, tmb, fmt)`,
|
| 1819 |
where the function `f` is defined as:
|
|
@@ -1833,21 +1916,20 @@ void f(basic_ios<charT, traits>& str, struct tm* tmb, const charT* fmt) {
|
|
| 1833 |
if (err != ios_base::goodbit)
|
| 1834 |
str.setstate(err);
|
| 1835 |
}
|
| 1836 |
```
|
| 1837 |
|
| 1838 |
-
The expression `in >> get_time(tmb, fmt)`
|
| 1839 |
`basic_istream<charT, traits>&` and value `in`.
|
| 1840 |
|
| 1841 |
``` cpp
|
| 1842 |
template<class charT> unspecified put_time(const struct tm* tmb, const charT* fmt);
|
| 1843 |
```
|
| 1844 |
|
| 1845 |
-
*
|
| 1846 |
-
type `struct tm`, and
|
| 1847 |
-
|
| 1848 |
-
elements.
|
| 1849 |
|
| 1850 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1851 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1852 |
`out << put_time(tmb, fmt)` behaves as if it called `f(out, tmb, fmt)`,
|
| 1853 |
where the function `f` is defined as:
|
|
@@ -1865,11 +1947,11 @@ void f(basic_ios<charT, traits>& str, const struct tm* tmb, const charT* fmt) {
|
|
| 1865 |
if (end.failed())
|
| 1866 |
str.setstate(ios_base::badbit);
|
| 1867 |
}
|
| 1868 |
```
|
| 1869 |
|
| 1870 |
-
The expression `out << put_time(tmb, fmt)`
|
| 1871 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1872 |
|
| 1873 |
### Quoted manipulators <a id="quoted.manip">[[quoted.manip]]</a>
|
| 1874 |
|
| 1875 |
[*Note 1*: Quoted manipulators provide string insertion and extraction
|
|
@@ -1892,13 +1974,12 @@ template <class charT, class traits>
|
|
| 1892 |
*Returns:* An object of unspecified type such that if `out` is an
|
| 1893 |
instance of `basic_ostream` with member type `char_type` the same as
|
| 1894 |
`charT` and with member type `traits_type`, which in the second and
|
| 1895 |
third forms is the same as `traits`, then the expression
|
| 1896 |
`out << quoted(s, delim, escape)` behaves as a formatted output
|
| 1897 |
-
function
|
| 1898 |
-
|
| 1899 |
-
elements:
|
| 1900 |
|
| 1901 |
- `delim`.
|
| 1902 |
- Each character in `s`. If the character to be output is equal to
|
| 1903 |
`escape` or `delim`, as determined by `traits_type::eq`, first output
|
| 1904 |
`escape`.
|
|
@@ -1906,11 +1987,11 @@ elements:
|
|
| 1906 |
|
| 1907 |
Let `x` be the number of elements initially in `seq`. Then padding is
|
| 1908 |
determined for `seq` as described in [[ostream.formatted.reqmts]],
|
| 1909 |
`seq` is inserted as if by calling `out.rdbuf()->sputn(seq, n)`, where
|
| 1910 |
`n` is the larger of `out.width()` and `x`, and `out.width(0)` is
|
| 1911 |
-
called. The expression `out << quoted(s, delim, escape)`
|
| 1912 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1913 |
|
| 1914 |
``` cpp
|
| 1915 |
template<class charT, class traits, class Allocator>
|
| 1916 |
unspecified quoted(basic_string<charT, traits, Allocator>& s,
|
|
@@ -1921,12 +2002,13 @@ template <class charT, class traits, class Allocator>
|
|
| 1921 |
|
| 1922 |
- If `in` is an instance of `basic_istream` with member types
|
| 1923 |
`char_type` and `traits_type` the same as `charT` and `traits`,
|
| 1924 |
respectively, then the expression `in >> quoted(s, delim, escape)`
|
| 1925 |
behaves as if it extracts the following characters from `in` using
|
| 1926 |
-
`operator>>(basic_istream<charT, traits>&, charT&)`
|
| 1927 |
-
which may throw `ios_base::failure`
|
|
|
|
| 1928 |
- If the first character extracted is equal to `delim`, as determined
|
| 1929 |
by `traits_type::eq`, then:
|
| 1930 |
- Turn off the `skipws` flag.
|
| 1931 |
- `s.clear()`
|
| 1932 |
- Until an unescaped `delim` character is reached or `!in`, extract
|
|
@@ -1940,11 +2022,10 @@ template <class charT, class traits, class Allocator>
|
|
| 1940 |
`char_type` and `traits_type` the same as `charT` and `traits`,
|
| 1941 |
respectively, then the expression `out << quoted(s, delim, escape)`
|
| 1942 |
behaves as specified for the
|
| 1943 |
`const basic_string<charT, traits, Allocator>&` overload of the
|
| 1944 |
`quoted` function.
|
| 1945 |
-
|
| 1946 |
-
|
| 1947 |
-
|
| 1948 |
-
`out << quoted(s, delim, escape)` shall have type
|
| 1949 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1950 |
|
|
|
|
| 39 |
template<class charT, class traits>
|
| 40 |
basic_ostream<charT, traits>& ends(basic_ostream<charT, traits>& os);
|
| 41 |
template<class charT, class traits>
|
| 42 |
basic_ostream<charT, traits>& flush(basic_ostream<charT, traits>& os);
|
| 43 |
|
| 44 |
+
template<class charT, class traits>
|
| 45 |
+
basic_ostream<charT, traits>& emit_on_flush(basic_ostream<charT, traits>& os);
|
| 46 |
+
template<class charT, class traits>
|
| 47 |
+
basic_ostream<charT, traits>& noemit_on_flush(basic_ostream<charT, traits>& os);
|
| 48 |
+
template<class charT, class traits>
|
| 49 |
+
basic_ostream<charT, traits>& flush_emit(basic_ostream<charT, traits>& os);
|
| 50 |
+
|
| 51 |
template<class charT, class traits, class T>
|
| 52 |
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&& os, const T& x);
|
| 53 |
}
|
| 54 |
```
|
| 55 |
|
|
|
|
| 59 |
namespace std {
|
| 60 |
// types T1, T2, ... are unspecified implementation types
|
| 61 |
T1 resetiosflags(ios_base::fmtflags mask);
|
| 62 |
T2 setiosflags (ios_base::fmtflags mask);
|
| 63 |
T3 setbase(int base);
|
| 64 |
+
template<class charT> T4 setfill(charT c);
|
| 65 |
T5 setprecision(int n);
|
| 66 |
T6 setw(int n);
|
| 67 |
template<class moneyT> T7 get_money(moneyT& mon, bool intl = false);
|
| 68 |
template<class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
|
| 69 |
template<class charT> T9 get_time(struct tm* tmb, const charT* fmt);
|
|
|
|
| 97 |
``` cpp
|
| 98 |
namespace std {
|
| 99 |
template<class charT, class traits = char_traits<charT>>
|
| 100 |
class basic_istream : virtual public basic_ios<charT, traits> {
|
| 101 |
public:
|
| 102 |
+
// types (inherited from basic_ios[ios])
|
| 103 |
using char_type = charT;
|
| 104 |
using int_type = typename traits::int_type;
|
| 105 |
using pos_type = typename traits::pos_type;
|
| 106 |
using off_type = typename traits::off_type;
|
| 107 |
using traits_type = traits;
|
| 108 |
|
| 109 |
// [istream.cons], constructor/destructor
|
| 110 |
explicit basic_istream(basic_streambuf<charT, traits>* sb);
|
| 111 |
virtual ~basic_istream();
|
| 112 |
|
| 113 |
+
// [istream.sentry], prefix/suffix
|
| 114 |
class sentry;
|
| 115 |
|
| 116 |
// [istream.formatted], formatted input
|
| 117 |
basic_istream<charT, traits>&
|
| 118 |
operator>>(basic_istream<charT, traits>& (*pf)(basic_istream<charT, traits>&));
|
|
|
|
| 162 |
basic_istream<charT, traits>& seekg(pos_type);
|
| 163 |
basic_istream<charT, traits>& seekg(off_type, ios_base::seekdir);
|
| 164 |
|
| 165 |
protected:
|
| 166 |
// [istream.cons], copy/move constructor
|
| 167 |
+
basic_istream(const basic_istream&) = delete;
|
| 168 |
basic_istream(basic_istream&& rhs);
|
| 169 |
|
| 170 |
// [istream.assign], assign and swap
|
| 171 |
+
basic_istream& operator=(const basic_istream&) = delete;
|
| 172 |
basic_istream& operator=(basic_istream&& rhs);
|
| 173 |
void swap(basic_istream& rhs);
|
| 174 |
};
|
| 175 |
|
| 176 |
// [istream.extractors], character extraction templates
|
|
|
|
| 179 |
template<class traits>
|
| 180 |
basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, unsigned char&);
|
| 181 |
template<class traits>
|
| 182 |
basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, signed char&);
|
| 183 |
|
| 184 |
+
template<class charT, class traits, size_t N>
|
| 185 |
+
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, charT(&)[N]);
|
| 186 |
+
template<class traits, size_t N>
|
| 187 |
+
basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, unsigned char(&)[N]);
|
| 188 |
+
template<class traits, size_t N>
|
| 189 |
+
basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, signed char(&)[N]);
|
| 190 |
}
|
| 191 |
```
|
| 192 |
|
| 193 |
The class template `basic_istream` defines a number of member function
|
| 194 |
signatures that assist in reading and interpreting input from sequences
|
|
|
|
| 201 |
or `rdbuf()->sgetc()`. They may use other public members of `istream`.
|
| 202 |
|
| 203 |
If `rdbuf()->sbumpc()` or `rdbuf()->sgetc()` returns `traits::eof()`,
|
| 204 |
then the input function, except as explicitly noted otherwise, completes
|
| 205 |
its actions and does `setstate(eofbit)`, which may throw
|
| 206 |
+
`ios_base::failure` [[iostate.flags]], before returning.
|
| 207 |
|
| 208 |
If one of these called functions throws an exception, then unless
|
| 209 |
+
explicitly noted otherwise, the input function sets `badbit` in the
|
| 210 |
+
error state. If `badbit` is set in `exceptions()`, the input function
|
| 211 |
+
rethrows the exception without completing its actions, otherwise it does
|
| 212 |
+
not throw anything and proceeds as if the called function had returned a
|
| 213 |
failure indication.
|
| 214 |
|
| 215 |
+
##### Constructors <a id="istream.cons">[[istream.cons]]</a>
|
| 216 |
|
| 217 |
``` cpp
|
| 218 |
explicit basic_istream(basic_streambuf<charT, traits>* sb);
|
| 219 |
```
|
| 220 |
|
| 221 |
+
*Effects:* Initializes the base class subobject with
|
| 222 |
+
`basic_ios::init(sb)` [[basic.ios.cons]].
|
|
|
|
| 223 |
|
| 224 |
+
*Ensures:* `gcount() == 0`.
|
| 225 |
|
| 226 |
``` cpp
|
| 227 |
basic_istream(basic_istream&& rhs);
|
| 228 |
```
|
| 229 |
|
| 230 |
+
*Effects:* Default constructs the base class, copies the `gcount()` from
|
| 231 |
+
`rhs`, calls `basic_ios<charT, traits>::move(rhs)` to initialize the
|
| 232 |
+
base class, and sets the `gcount()` for `rhs` to 0.
|
|
|
|
| 233 |
|
| 234 |
``` cpp
|
| 235 |
virtual ~basic_istream();
|
| 236 |
```
|
| 237 |
|
|
|
|
|
|
|
| 238 |
*Remarks:* Does not perform any operations of `rdbuf()`.
|
| 239 |
|
| 240 |
+
##### Assignment and swap <a id="istream.assign">[[istream.assign]]</a>
|
| 241 |
|
| 242 |
``` cpp
|
| 243 |
basic_istream& operator=(basic_istream&& rhs);
|
| 244 |
```
|
| 245 |
|
| 246 |
+
*Effects:* Equivalent to: `swap(rhs)`.
|
| 247 |
|
| 248 |
*Returns:* `*this`.
|
| 249 |
|
| 250 |
``` cpp
|
| 251 |
void swap(basic_istream& rhs);
|
| 252 |
```
|
| 253 |
|
| 254 |
*Effects:* Calls `basic_ios<charT, traits>::swap(rhs)`. Exchanges the
|
| 255 |
values returned by `gcount()` and `rhs.gcount()`.
|
| 256 |
|
| 257 |
+
##### Class `basic_istream::sentry` <a id="istream.sentry">[[istream.sentry]]</a>
|
| 258 |
|
| 259 |
``` cpp
|
| 260 |
namespace std {
|
| 261 |
template<class charT, class traits = char_traits<charT>>
|
| 262 |
class basic_istream<charT, traits>::sentry {
|
|
|
|
| 263 |
bool ok_; // exposition only
|
| 264 |
public:
|
| 265 |
explicit sentry(basic_istream<charT, traits>& is, bool noskipws = false);
|
| 266 |
~sentry();
|
| 267 |
explicit operator bool() const { return ok_; }
|
|
|
|
| 312 |
```
|
| 313 |
|
| 314 |
If, after any preparation is completed, `is.good()` is `true`,
|
| 315 |
`ok_ != false` otherwise, `ok_ == false`. During preparation, the
|
| 316 |
constructor may call `setstate(failbit)` (which may throw
|
| 317 |
+
`ios_base::failure` [[iostate.flags]]).[^19]
|
| 318 |
|
| 319 |
``` cpp
|
| 320 |
~sentry();
|
| 321 |
```
|
| 322 |
|
|
|
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
explicit operator bool() const;
|
| 327 |
```
|
| 328 |
|
| 329 |
+
*Returns:* `ok_`.
|
| 330 |
|
| 331 |
#### Formatted input functions <a id="istream.formatted">[[istream.formatted]]</a>
|
| 332 |
|
| 333 |
##### Common requirements <a id="istream.formatted.reqmts">[[istream.formatted.reqmts]]</a>
|
| 334 |
|
| 335 |
Each formatted input function begins execution by constructing an object
|
| 336 |
of class `sentry` with the `noskipws` (second) argument `false`. If the
|
| 337 |
`sentry` object returns `true`, when converted to a value of type
|
| 338 |
`bool`, the function endeavors to obtain the requested input. If an
|
| 339 |
+
exception is thrown during input then `ios_base::badbit` is turned
|
| 340 |
+
on[^20] in `*this`’s error state. If `(exceptions()&badbit) != 0` then
|
| 341 |
+
the exception is rethrown. In any case, the formatted input function
|
| 342 |
destroys the `sentry` object. If no exception has been thrown, it
|
| 343 |
returns `*this`.
|
| 344 |
|
| 345 |
##### Arithmetic extractors <a id="istream.formatted.arithmetic">[[istream.formatted.arithmetic]]</a>
|
| 346 |
|
|
|
|
| 357 |
operator>>(bool& val);
|
| 358 |
operator>>(void*& val);
|
| 359 |
```
|
| 360 |
|
| 361 |
As in the case of the inserters, these extractors depend on the locale’s
|
| 362 |
+
`num_get<>` [[locale.num.get]] object to perform parsing the input
|
| 363 |
stream data. These extractors behave as formatted input functions (as
|
| 364 |
described in [[istream.formatted.reqmts]]). After a sentry object is
|
| 365 |
constructed, the conversion occurs as if performed by the following code
|
| 366 |
fragment:
|
| 367 |
|
|
|
|
| 461 |
in [[istream.formatted.reqmts]]).
|
| 462 |
|
| 463 |
*Returns:* `*this`.
|
| 464 |
|
| 465 |
``` cpp
|
| 466 |
+
template<class charT, class traits, size_t N>
|
| 467 |
+
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& in, charT (&s)[N]);
|
| 468 |
+
template<class traits, size_t N>
|
| 469 |
+
basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, unsigned char (&s)[N]);
|
| 470 |
+
template<class traits, size_t N>
|
| 471 |
+
basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, signed char (&s)[N]);
|
| 472 |
```
|
| 473 |
|
| 474 |
*Effects:* Behaves like a formatted input member (as described
|
| 475 |
in [[istream.formatted.reqmts]]) of `in`. After a `sentry` object is
|
| 476 |
+
constructed, `operator>>` extracts characters and stores them into `s`.
|
| 477 |
+
If `width()` is greater than zero, `n` is `min(size_t(width()), N)`.
|
| 478 |
+
Otherwise `n` is `N`. `n` is the maximum number of characters stored.
|
|
|
|
|
|
|
|
|
|
| 479 |
|
| 480 |
Characters are extracted and stored until any of the following occurs:
|
| 481 |
|
| 482 |
- `n-1` characters are stored;
|
| 483 |
- end of file occurs on the input sequence;
|
|
|
|
| 487 |
`operator>>` then stores a null byte (`charT()`) in the next position,
|
| 488 |
which may be the first position if no characters were extracted.
|
| 489 |
`operator>>` then calls `width(0)`.
|
| 490 |
|
| 491 |
If the function extracted no characters, it calls `setstate(failbit)`,
|
| 492 |
+
which may throw `ios_base::failure` [[iostate.flags]].
|
| 493 |
|
| 494 |
*Returns:* `in`.
|
| 495 |
|
| 496 |
``` cpp
|
| 497 |
template<class charT, class traits>
|
|
|
|
| 511 |
|
| 512 |
``` cpp
|
| 513 |
basic_istream<charT, traits>& operator>>(basic_streambuf<charT, traits>* sb);
|
| 514 |
```
|
| 515 |
|
| 516 |
+
*Effects:* Behaves as an unformatted input
|
| 517 |
+
function [[istream.unformatted]]. If `sb` is null, calls
|
| 518 |
+
`setstate(failbit)`, which may throw `ios_base::failure`
|
| 519 |
+
[[iostate.flags]]. After a sentry object is constructed, extracts
|
| 520 |
+
characters from `*this` and inserts them in the output sequence
|
| 521 |
+
controlled by `sb`. Characters are extracted and inserted until any of
|
| 522 |
+
the following occurs:
|
| 523 |
|
| 524 |
- end-of-file occurs on the input sequence;
|
| 525 |
- inserting in the output sequence fails (in which case the character to
|
| 526 |
be inserted is not extracted);
|
| 527 |
- an exception occurs (in which case the exception is caught).
|
| 528 |
|
| 529 |
If the function inserts no characters, it calls `setstate(failbit)`,
|
| 530 |
+
which may throw `ios_base::failure` [[iostate.flags]]. If it inserted no
|
| 531 |
+
characters because it caught an exception thrown while extracting
|
| 532 |
+
characters from `*this` and `failbit` is set in `exceptions()`
|
| 533 |
+
[[iostate.flags]], then the caught exception is rethrown.
|
|
|
|
| 534 |
|
| 535 |
*Returns:* `*this`.
|
| 536 |
|
| 537 |
#### Unformatted input functions <a id="istream.unformatted">[[istream.unformatted]]</a>
|
| 538 |
|
|
|
|
| 545 |
a value of type `bool`, the function returns without attempting to
|
| 546 |
obtain any input. In either case the number of extracted characters is
|
| 547 |
set to 0; unformatted input functions taking a character array of
|
| 548 |
nonzero size as an argument shall also store a null character (using
|
| 549 |
`charT()`) in the first location of the array. If an exception is thrown
|
| 550 |
+
during input then `ios_base::badbit` is turned on[^23] in `*this`’s
|
| 551 |
+
error state. (Exceptions thrown from `basic_ios<>::clear()` are not
|
| 552 |
+
caught or rethrown.) If `(exceptions()&badbit) != 0` then the exception
|
| 553 |
+
is rethrown. It also counts the number of characters extracted. If no
|
| 554 |
exception has been thrown it ends by storing the count in a member
|
| 555 |
object and returning the value specified. In any event the `sentry`
|
| 556 |
object is destroyed before leaving the unformatted input function.
|
| 557 |
|
| 558 |
``` cpp
|
|
|
|
| 570 |
```
|
| 571 |
|
| 572 |
*Effects:* Behaves as an unformatted input function (as described
|
| 573 |
above). After constructing a sentry object, extracts a character `c`, if
|
| 574 |
one is available. Otherwise, the function calls `setstate(failbit)`,
|
| 575 |
+
which may throw `ios_base::failure` [[iostate.flags]].
|
| 576 |
|
| 577 |
*Returns:* `c` if available, otherwise `traits::eof()`.
|
| 578 |
|
| 579 |
``` cpp
|
| 580 |
basic_istream<charT, traits>& get(char_type& c);
|
| 581 |
```
|
| 582 |
|
| 583 |
*Effects:* Behaves as an unformatted input function (as described
|
| 584 |
above). After constructing a sentry object, extracts a character, if one
|
| 585 |
is available, and assigns it to `c`.[^24] Otherwise, the function calls
|
| 586 |
+
`setstate(failbit)` (which may throw `ios_base::failure`
|
| 587 |
+
[[iostate.flags]]).
|
| 588 |
|
| 589 |
*Returns:* `*this`.
|
| 590 |
|
| 591 |
``` cpp
|
| 592 |
basic_istream<charT, traits>& get(char_type* s, streamsize n, char_type delim);
|
|
|
|
| 603 |
calls `setstate(eofbit)`);
|
| 604 |
- `traits::eq(c, delim)` for the next available input character `c` (in
|
| 605 |
which case `c` is not extracted).
|
| 606 |
|
| 607 |
If the function stores no characters, it calls `setstate(failbit)`
|
| 608 |
+
(which may throw `ios_base::failure` [[iostate.flags]]). In any case, if
|
| 609 |
+
`n` is greater than zero it then stores a null character into the next
|
| 610 |
+
successive location of the array.
|
| 611 |
|
| 612 |
*Returns:* `*this`.
|
| 613 |
|
| 614 |
``` cpp
|
| 615 |
basic_istream<charT, traits>& get(char_type* s, streamsize n);
|
|
|
|
| 635 |
which case `c` is not extracted);
|
| 636 |
- an exception occurs (in which case, the exception is caught but not
|
| 637 |
rethrown).
|
| 638 |
|
| 639 |
If the function inserts no characters, it calls `setstate(failbit)`,
|
| 640 |
+
which may throw `ios_base::failure` [[iostate.flags]].
|
| 641 |
|
| 642 |
*Returns:* `*this`.
|
| 643 |
|
| 644 |
``` cpp
|
| 645 |
basic_istream<charT, traits>& get(basic_streambuf<char_type, traits>& sb);
|
|
|
|
| 668 |
the function calls `setstate(failbit)`).
|
| 669 |
|
| 670 |
These conditions are tested in the order shown.[^28]
|
| 671 |
|
| 672 |
If the function extracts no characters, it calls `setstate(failbit)`
|
| 673 |
+
(which may throw `ios_base::failure` [[iostate.flags]]).[^29]
|
| 674 |
|
| 675 |
In any case, if `n` is greater than zero, it then stores a null
|
| 676 |
character (using `charT()`) into the next successive location of the
|
| 677 |
array.
|
| 678 |
|
|
|
|
| 720 |
*Effects:* Behaves as an unformatted input function (as described
|
| 721 |
above). After constructing a sentry object, extracts characters and
|
| 722 |
discards them. Characters are extracted until any of the following
|
| 723 |
occurs:
|
| 724 |
|
| 725 |
+
- `n != numeric_limits<streamsize>::max()` [[numeric.limits]] and `n`
|
| 726 |
characters have been extracted so far
|
| 727 |
- end-of-file occurs on the input sequence (in which case the function
|
| 728 |
+
calls `setstate(eofbit)`, which may throw `ios_base::failure`
|
| 729 |
+
[[iostate.flags]]);
|
| 730 |
- `traits::eq_int_type(traits::to_int_type(c), delim)` for the next
|
| 731 |
available input character `c` (in which case `c` is extracted).
|
| 732 |
|
| 733 |
*Remarks:* The last condition will never occur if
|
| 734 |
`traits::eq_int_type(delim, traits::eof())`.
|
|
|
|
| 758 |
extracted and stored until either of the following occurs:
|
| 759 |
|
| 760 |
- `n` characters are stored;
|
| 761 |
- end-of-file occurs on the input sequence (in which case the function
|
| 762 |
calls `setstate(failbit | eofbit)`, which may throw
|
| 763 |
+
`ios_base::failure` [[iostate.flags]]).
|
| 764 |
|
| 765 |
*Returns:* `*this`.
|
| 766 |
|
| 767 |
``` cpp
|
| 768 |
streamsize readsome(char_type* s, streamsize n);
|
|
|
|
| 772 |
above). After constructing a sentry object, if `!good()` calls
|
| 773 |
`setstate(failbit)` which may throw an exception, and return. Otherwise
|
| 774 |
extracts characters and stores them into successive locations of an
|
| 775 |
array whose first element is designated by `s`. If
|
| 776 |
`rdbuf()->in_avail() == -1`, calls `setstate(eofbit)` (which may throw
|
| 777 |
+
`ios_base::failure` [[iostate.flags]]), and extracts no characters;
|
| 778 |
|
| 779 |
- If `rdbuf()->in_avail() == 0`, extracts no characters
|
| 780 |
- If `rdbuf()->in_avail() > 0`, extracts `min(rdbuf()->in_avail(), n))`.
|
| 781 |
|
| 782 |
*Returns:* The number of characters extracted.
|
|
|
|
| 787 |
|
| 788 |
*Effects:* Behaves as an unformatted input function (as described
|
| 789 |
above), except that the function first clears `eofbit`. After
|
| 790 |
constructing a sentry object, if `!good()` calls `setstate(failbit)`
|
| 791 |
which may throw an exception, and return. If `rdbuf()` is not null,
|
| 792 |
+
calls `rdbuf()->sputbackc(c)`. If `rdbuf()` is null, or if `sputbackc`
|
| 793 |
returns `traits::eof()`, calls `setstate(badbit)` (which may throw
|
| 794 |
+
`ios_base::failure` [[iostate.flags]]).
|
| 795 |
|
| 796 |
[*Note 1*: This function extracts no characters, so the value returned
|
| 797 |
by the next call to `gcount()` is 0. — *end note*]
|
| 798 |
|
| 799 |
*Returns:* `*this`.
|
|
|
|
| 804 |
|
| 805 |
*Effects:* Behaves as an unformatted input function (as described
|
| 806 |
above), except that the function first clears `eofbit`. After
|
| 807 |
constructing a sentry object, if `!good()` calls `setstate(failbit)`
|
| 808 |
which may throw an exception, and return. If `rdbuf()` is not null,
|
| 809 |
+
calls `rdbuf()->sungetc()`. If `rdbuf()` is null, or if `sungetc`
|
| 810 |
returns `traits::eof()`, calls `setstate(badbit)` (which may throw
|
| 811 |
+
`ios_base::failure` [[iostate.flags]]).
|
| 812 |
|
| 813 |
[*Note 2*: This function extracts no characters, so the value returned
|
| 814 |
by the next call to `gcount()` is 0. — *end note*]
|
| 815 |
|
| 816 |
*Returns:* `*this`.
|
|
|
|
| 823 |
above), except that it does not count the number of characters extracted
|
| 824 |
and does not affect the value returned by subsequent calls to
|
| 825 |
`gcount()`. After constructing a sentry object, if `rdbuf()` is a null
|
| 826 |
pointer, returns `-1`. Otherwise, calls `rdbuf()->pubsync()` and, if
|
| 827 |
that function returns `-1` calls `setstate(badbit)` (which may throw
|
| 828 |
+
`ios_base::failure` [[iostate.flags]], and returns `-1`. Otherwise,
|
| 829 |
returns zero.
|
| 830 |
|
| 831 |
``` cpp
|
| 832 |
pos_type tellg();
|
| 833 |
```
|
|
|
|
| 871 |
|
| 872 |
*Returns:* `*this`.
|
| 873 |
|
| 874 |
#### Standard `basic_istream` manipulators <a id="istream.manip">[[istream.manip]]</a>
|
| 875 |
|
| 876 |
+
Each instantiation of the function template specified in this subclause
|
| 877 |
+
is a designated addressable function [[namespace.std]].
|
| 878 |
+
|
| 879 |
``` cpp
|
| 880 |
template<class charT, class traits>
|
| 881 |
basic_istream<charT, traits>& ws(basic_istream<charT, traits>& is);
|
| 882 |
```
|
| 883 |
|
| 884 |
+
*Effects:* Behaves as an unformatted input
|
| 885 |
+
function [[istream.unformatted]], except that it does not count the
|
| 886 |
+
number of characters extracted and does not affect the value returned by
|
| 887 |
+
subsequent calls to `is.gcount()`. After constructing a sentry object
|
| 888 |
extracts characters as long as the next available character `c` is
|
| 889 |
whitespace or until there are no more characters in the sequence.
|
| 890 |
Whitespace characters are distinguished with the same criterion as used
|
| 891 |
+
by `sentry::sentry` [[istream.sentry]]. If `ws` stops extracting
|
| 892 |
characters because there are no more available it sets `eofbit`, but not
|
| 893 |
`failbit`.
|
| 894 |
|
| 895 |
*Returns:* `is`.
|
| 896 |
|
| 897 |
#### Rvalue stream extraction <a id="istream.rvalue">[[istream.rvalue]]</a>
|
| 898 |
|
| 899 |
``` cpp
|
| 900 |
+
template<class Istream, class T>
|
| 901 |
+
Istream&& operator>>(Istream&& is, T&& x);
|
| 902 |
```
|
| 903 |
|
| 904 |
+
*Constraints:* The expression `is >> std::forward<T>(x)` is well-formed
|
| 905 |
+
when treated as an unevaluated operand and `Istream` is publicly and
|
| 906 |
+
unambiguously derived from `ios_base`.
|
| 907 |
+
|
| 908 |
*Effects:* Equivalent to:
|
| 909 |
|
| 910 |
``` cpp
|
| 911 |
is >> std::forward<T>(x);
|
| 912 |
+
return std::move(is);
|
| 913 |
```
|
| 914 |
|
|
|
|
|
|
|
|
|
|
| 915 |
#### Class template `basic_iostream` <a id="iostreamclass">[[iostreamclass]]</a>
|
| 916 |
|
| 917 |
``` cpp
|
| 918 |
namespace std {
|
| 919 |
template<class charT, class traits = char_traits<charT>>
|
|
|
|
| 933 |
// [iostream.dest], destructor
|
| 934 |
virtual ~basic_iostream();
|
| 935 |
|
| 936 |
protected:
|
| 937 |
// [iostream.cons], constructor
|
| 938 |
+
basic_iostream(const basic_iostream&) = delete;
|
| 939 |
basic_iostream(basic_iostream&& rhs);
|
| 940 |
|
| 941 |
// [iostream.assign], assign and swap
|
| 942 |
+
basic_iostream& operator=(const basic_iostream&) = delete;
|
| 943 |
basic_iostream& operator=(basic_iostream&& rhs);
|
| 944 |
void swap(basic_iostream& rhs);
|
| 945 |
};
|
| 946 |
}
|
| 947 |
```
|
| 948 |
|
| 949 |
The class template `basic_iostream` inherits a number of functions that
|
| 950 |
allow reading input and writing output to sequences controlled by a
|
| 951 |
stream buffer.
|
| 952 |
|
| 953 |
+
##### Constructors <a id="iostream.cons">[[iostream.cons]]</a>
|
| 954 |
|
| 955 |
``` cpp
|
| 956 |
explicit basic_iostream(basic_streambuf<charT, traits>* sb);
|
| 957 |
```
|
| 958 |
|
| 959 |
+
*Effects:* Initializes the base class subobjects with
|
| 960 |
+
`basic_istream<charT, traits>(sb)` [[istream]] and
|
| 961 |
+
`basic_ostream<charT, traits>(sb)` [[ostream]].
|
|
|
|
| 962 |
|
| 963 |
+
*Ensures:* `rdbuf() == sb` and `gcount() == 0`.
|
| 964 |
|
| 965 |
``` cpp
|
| 966 |
basic_iostream(basic_iostream&& rhs);
|
| 967 |
```
|
| 968 |
|
| 969 |
*Effects:* Move constructs from the rvalue `rhs` by constructing the
|
| 970 |
`basic_istream` base class with `move(rhs)`.
|
| 971 |
|
| 972 |
+
##### Destructor <a id="iostream.dest">[[iostream.dest]]</a>
|
| 973 |
|
| 974 |
``` cpp
|
| 975 |
virtual ~basic_iostream();
|
| 976 |
```
|
| 977 |
|
|
|
|
|
|
|
| 978 |
*Remarks:* Does not perform any operations on `rdbuf()`.
|
| 979 |
|
| 980 |
+
##### Assignment and swap <a id="iostream.assign">[[iostream.assign]]</a>
|
| 981 |
|
| 982 |
``` cpp
|
| 983 |
basic_iostream& operator=(basic_iostream&& rhs);
|
| 984 |
```
|
| 985 |
|
| 986 |
+
*Effects:* Equivalent to: `swap(rhs)`.
|
| 987 |
|
| 988 |
``` cpp
|
| 989 |
void swap(basic_iostream& rhs);
|
| 990 |
```
|
| 991 |
|
|
|
|
| 1002 |
``` cpp
|
| 1003 |
namespace std {
|
| 1004 |
template<class charT, class traits = char_traits<charT>>
|
| 1005 |
class basic_ostream : virtual public basic_ios<charT, traits> {
|
| 1006 |
public:
|
| 1007 |
+
// types (inherited from basic_ios[ios])
|
| 1008 |
using char_type = charT;
|
| 1009 |
using int_type = typename traits::int_type;
|
| 1010 |
using pos_type = typename traits::pos_type;
|
| 1011 |
using off_type = typename traits::off_type;
|
| 1012 |
using traits_type = traits;
|
| 1013 |
|
| 1014 |
// [ostream.cons], constructor/destructor
|
| 1015 |
explicit basic_ostream(basic_streambuf<char_type, traits>* sb);
|
| 1016 |
virtual ~basic_ostream();
|
| 1017 |
|
| 1018 |
+
// [ostream.sentry], prefix/suffix
|
| 1019 |
class sentry;
|
| 1020 |
|
| 1021 |
// [ostream.formatted], formatted output
|
| 1022 |
basic_ostream<charT, traits>&
|
| 1023 |
operator<<(basic_ostream<charT, traits>& (*pf)(basic_ostream<charT, traits>&));
|
|
|
|
| 1054 |
basic_ostream<charT, traits>& seekp(pos_type);
|
| 1055 |
basic_ostream<charT, traits>& seekp(off_type, ios_base::seekdir);
|
| 1056 |
|
| 1057 |
protected:
|
| 1058 |
// [ostream.cons], copy/move constructor
|
| 1059 |
+
basic_ostream(const basic_ostream&) = delete;
|
| 1060 |
basic_ostream(basic_ostream&& rhs);
|
| 1061 |
|
| 1062 |
// [ostream.assign], assign and swap
|
| 1063 |
+
basic_ostream& operator=(const basic_ostream&) = delete;
|
| 1064 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 1065 |
void swap(basic_ostream& rhs);
|
| 1066 |
};
|
| 1067 |
|
| 1068 |
// [ostream.inserters.character], character inserters
|
|
|
|
| 1076 |
template<class traits>
|
| 1077 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, signed char);
|
| 1078 |
template<class traits>
|
| 1079 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, unsigned char);
|
| 1080 |
|
| 1081 |
+
template<class traits>
|
| 1082 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, wchar_t) = delete;
|
| 1083 |
+
template<class traits>
|
| 1084 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char8_t) = delete;
|
| 1085 |
+
template<class traits>
|
| 1086 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char16_t) = delete;
|
| 1087 |
+
template<class traits>
|
| 1088 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char32_t) = delete;
|
| 1089 |
+
template<class traits>
|
| 1090 |
+
basic_ostream<wchar_t, traits>&
|
| 1091 |
+
operator<<(basic_ostream<wchar_t, traits>&, char8_t) = delete;
|
| 1092 |
+
template<class traits>
|
| 1093 |
+
basic_ostream<wchar_t, traits>&
|
| 1094 |
+
operator<<(basic_ostream<wchar_t, traits>&, char16_t) = delete;
|
| 1095 |
+
template<class traits>
|
| 1096 |
+
basic_ostream<wchar_t, traits>&
|
| 1097 |
+
operator<<(basic_ostream<wchar_t, traits>&, char32_t) = delete;
|
| 1098 |
+
|
| 1099 |
template<class charT, class traits>
|
| 1100 |
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const charT*);
|
| 1101 |
template<class charT, class traits>
|
| 1102 |
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const char*);
|
| 1103 |
template<class traits>
|
|
|
|
| 1105 |
|
| 1106 |
template<class traits>
|
| 1107 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const signed char*);
|
| 1108 |
template<class traits>
|
| 1109 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const unsigned char*);
|
| 1110 |
+
|
| 1111 |
+
template<class traits>
|
| 1112 |
+
basic_ostream<char, traits>&
|
| 1113 |
+
operator<<(basic_ostream<char, traits>&, const wchar_t*) = delete;
|
| 1114 |
+
template<class traits>
|
| 1115 |
+
basic_ostream<char, traits>&
|
| 1116 |
+
operator<<(basic_ostream<char, traits>&, const char8_t*) = delete;
|
| 1117 |
+
template<class traits>
|
| 1118 |
+
basic_ostream<char, traits>&
|
| 1119 |
+
operator<<(basic_ostream<char, traits>&, const char16_t*) = delete;
|
| 1120 |
+
template<class traits>
|
| 1121 |
+
basic_ostream<char, traits>&
|
| 1122 |
+
operator<<(basic_ostream<char, traits>&, const char32_t*) = delete;
|
| 1123 |
+
template<class traits>
|
| 1124 |
+
basic_ostream<wchar_t, traits>&
|
| 1125 |
+
operator<<(basic_ostream<wchar_t, traits>&, const char8_t*) = delete;
|
| 1126 |
+
template<class traits>
|
| 1127 |
+
basic_ostream<wchar_t, traits>&
|
| 1128 |
+
operator<<(basic_ostream<wchar_t, traits>&, const char16_t*) = delete;
|
| 1129 |
+
template<class traits>
|
| 1130 |
+
basic_ostream<wchar_t, traits>&
|
| 1131 |
+
operator<<(basic_ostream<wchar_t, traits>&, const char32_t*) = delete;
|
| 1132 |
}
|
| 1133 |
```
|
| 1134 |
|
| 1135 |
The class template `basic_ostream` defines a number of member function
|
| 1136 |
signatures that assist in formatting and writing output to output
|
|
|
|
| 1143 |
`rdbuf()->sputc(int_type)`. They may use other public members of
|
| 1144 |
`basic_ostream` except that they shall not invoke any virtual members of
|
| 1145 |
`rdbuf()` except `overflow()`, `xsputn()`, and `sync()`.
|
| 1146 |
|
| 1147 |
If one of these called functions throws an exception, then unless
|
| 1148 |
+
explicitly noted otherwise the output function sets `badbit` in the
|
| 1149 |
+
error state. If `badbit` is set in `exceptions()`, the output function
|
| 1150 |
+
rethrows the exception without completing its actions, otherwise it does
|
| 1151 |
+
not throw anything and proceeds as if the called function had returned a
|
| 1152 |
+
failure indication.
|
| 1153 |
|
| 1154 |
+
[*Note 1*: The deleted overloads of `operator<<` prevent formatting
|
| 1155 |
+
characters as integers and strings as pointers. — *end note*]
|
| 1156 |
+
|
| 1157 |
+
##### Constructors <a id="ostream.cons">[[ostream.cons]]</a>
|
| 1158 |
|
| 1159 |
``` cpp
|
| 1160 |
explicit basic_ostream(basic_streambuf<charT, traits>* sb);
|
| 1161 |
```
|
| 1162 |
|
| 1163 |
+
*Effects:* Initializes the base class subobject with
|
| 1164 |
+
`basic_ios<charT, traits>::init(sb)` [[basic.ios.cons]].
|
|
|
|
| 1165 |
|
| 1166 |
+
*Ensures:* `rdbuf() == sb`.
|
| 1167 |
|
| 1168 |
``` cpp
|
| 1169 |
basic_ostream(basic_ostream&& rhs);
|
| 1170 |
```
|
| 1171 |
|
|
|
|
| 1175 |
|
| 1176 |
``` cpp
|
| 1177 |
virtual ~basic_ostream();
|
| 1178 |
```
|
| 1179 |
|
|
|
|
|
|
|
| 1180 |
*Remarks:* Does not perform any operations on `rdbuf()`.
|
| 1181 |
|
| 1182 |
+
##### Assignment and swap <a id="ostream.assign">[[ostream.assign]]</a>
|
| 1183 |
|
| 1184 |
``` cpp
|
| 1185 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 1186 |
```
|
| 1187 |
|
| 1188 |
+
*Effects:* Equivalent to: `swap(rhs)`.
|
| 1189 |
|
| 1190 |
*Returns:* `*this`.
|
| 1191 |
|
| 1192 |
``` cpp
|
| 1193 |
void swap(basic_ostream& rhs);
|
| 1194 |
```
|
| 1195 |
|
| 1196 |
*Effects:* Calls `basic_ios<charT, traits>::swap(rhs)`.
|
| 1197 |
|
| 1198 |
+
##### Class `basic_ostream::sentry` <a id="ostream.sentry">[[ostream.sentry]]</a>
|
| 1199 |
|
| 1200 |
``` cpp
|
| 1201 |
namespace std {
|
| 1202 |
template<class charT, class traits = char_traits<charT>>
|
| 1203 |
class basic_ostream<charT, traits>::sentry {
|
|
|
|
| 1224 |
If `os.tie()` is not a null pointer, calls `os.tie()->flush()`.[^31]
|
| 1225 |
|
| 1226 |
If, after any preparation is completed, `os.good()` is `true`,
|
| 1227 |
`ok_ == true` otherwise, `ok_ == false`. During preparation, the
|
| 1228 |
constructor may call `setstate(failbit)` (which may throw
|
| 1229 |
+
`ios_base::failure` [[iostate.flags]]).[^32]
|
| 1230 |
|
| 1231 |
``` cpp
|
| 1232 |
~sentry();
|
| 1233 |
```
|
| 1234 |
|
|
|
|
| 1241 |
explicit operator bool() const;
|
| 1242 |
```
|
| 1243 |
|
| 1244 |
*Effects:* Returns `ok_`.
|
| 1245 |
|
| 1246 |
+
##### Seek members <a id="ostream.seeks">[[ostream.seeks]]</a>
|
| 1247 |
|
| 1248 |
Each seek member function begins execution by constructing an object of
|
| 1249 |
class `sentry`. It returns by destroying the `sentry` object.
|
| 1250 |
|
| 1251 |
``` cpp
|
|
|
|
| 1284 |
Each formatted output function begins execution by constructing an
|
| 1285 |
object of class `sentry`. If this object returns `true` when converted
|
| 1286 |
to a value of type `bool`, the function endeavors to generate the
|
| 1287 |
requested output. If the generation fails, then the formatted output
|
| 1288 |
function does `setstate(ios_base::failbit)`, which might throw an
|
| 1289 |
+
exception. If an exception is thrown during output, then
|
| 1290 |
+
`ios_base::badbit` is turned on[^33] in `*this`’s error state. If
|
| 1291 |
`(exceptions()&badbit) != 0` then the exception is rethrown. Whether or
|
| 1292 |
not an exception is thrown, the `sentry` object is destroyed before
|
| 1293 |
leaving the formatted output function. If no exception is thrown, the
|
| 1294 |
result of the formatted output function is `*this`.
|
| 1295 |
|
|
|
|
| 1430 |
|
| 1431 |
``` cpp
|
| 1432 |
basic_ostream<charT, traits>& operator<<(basic_streambuf<charT, traits>* sb);
|
| 1433 |
```
|
| 1434 |
|
| 1435 |
+
*Effects:* Behaves as an unformatted output
|
| 1436 |
+
function [[ostream.unformatted]]. After the sentry object is
|
| 1437 |
+
constructed, if `sb` is null calls `setstate(badbit)` (which may throw
|
| 1438 |
`ios_base::failure`).
|
| 1439 |
|
| 1440 |
Gets characters from `sb` and inserts them in `*this`. Characters are
|
| 1441 |
read from `sb` and inserted until any of the following occurs:
|
| 1442 |
|
|
|
|
| 1444 |
- inserting in the output sequence fails (in which case the character to
|
| 1445 |
be inserted is not extracted);
|
| 1446 |
- an exception occurs while getting a character from `sb`.
|
| 1447 |
|
| 1448 |
If the function inserts no characters, it calls `setstate(failbit)`
|
| 1449 |
+
(which may throw `ios_base::failure` [[iostate.flags]]). If an exception
|
| 1450 |
+
was thrown while extracting a character, the function sets `failbit` in
|
| 1451 |
+
the error state, and if `failbit` is set in `exceptions()` the caught
|
| 1452 |
+
exception is rethrown.
|
| 1453 |
|
| 1454 |
*Returns:* `*this`.
|
| 1455 |
|
| 1456 |
``` cpp
|
| 1457 |
basic_ostream<charT, traits>& operator<<(nullptr_t);
|
|
|
|
| 1461 |
|
| 1462 |
``` cpp
|
| 1463 |
return *this << s;
|
| 1464 |
```
|
| 1465 |
|
| 1466 |
+
where `s` is an *implementation-defined* NTCTS [[defns.ntcts]].
|
| 1467 |
|
| 1468 |
##### Character inserter function templates <a id="ostream.inserters.character">[[ostream.inserters.character]]</a>
|
| 1469 |
|
| 1470 |
``` cpp
|
| 1471 |
template<class charT, class traits>
|
|
|
|
| 1481 |
template<class traits>
|
| 1482 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, unsigned char c);
|
| 1483 |
```
|
| 1484 |
|
| 1485 |
*Effects:* Behaves as a formatted output
|
| 1486 |
+
function [[ostream.formatted.reqmts]] of `out`. Constructs a character
|
| 1487 |
+
sequence `seq`. If `c` has type `char` and the character type of the
|
| 1488 |
+
stream is not `char`, then `seq` consists of `out.widen(c)`; otherwise
|
| 1489 |
+
`seq` consists of `c`. Determines padding for `seq` as described
|
| 1490 |
+
in [[ostream.formatted.reqmts]]. Inserts `seq` into `out`. Calls
|
| 1491 |
+
`os.width(0)`.
|
| 1492 |
|
| 1493 |
*Returns:* `out`.
|
| 1494 |
|
| 1495 |
``` cpp
|
| 1496 |
template<class charT, class traits>
|
|
|
|
| 1504 |
template<class traits>
|
| 1505 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out,
|
| 1506 |
const unsigned char* s);
|
| 1507 |
```
|
| 1508 |
|
| 1509 |
+
*Preconditions:* `s` is not a null pointer.
|
| 1510 |
|
| 1511 |
*Effects:* Behaves like a formatted inserter (as described
|
| 1512 |
in [[ostream.formatted.reqmts]]) of `out`. Creates a character sequence
|
| 1513 |
`seq` of `n` characters starting at `s`, each widened using
|
| 1514 |
+
`out.widen()` [[basic.ios.members]], where `n` is the number that would
|
| 1515 |
+
be computed as if by:
|
| 1516 |
|
| 1517 |
- `traits::length(s)` for the overload where the first argument is of
|
| 1518 |
type `basic_ostream<charT, traits>&` and the second is of type
|
| 1519 |
`const charT*`, and also for the overload where the first argument is
|
| 1520 |
of type `basic_ostream<char, traits>&` and the second is of type
|
|
|
|
| 1535 |
|
| 1536 |
Each unformatted output function begins execution by constructing an
|
| 1537 |
object of class `sentry`. If this object returns `true`, while
|
| 1538 |
converting to a value of type `bool`, the function endeavors to generate
|
| 1539 |
the requested output. If an exception is thrown during output, then
|
| 1540 |
+
`ios_base::badbit` is turned on[^36] in `*this`’s error state. If
|
| 1541 |
`(exceptions() & badbit) != 0` then the exception is rethrown. In any
|
| 1542 |
case, the unformatted output function ends by destroying the sentry
|
| 1543 |
object, then, if no exception was thrown, returning the value specified
|
| 1544 |
for the unformatted output function.
|
| 1545 |
|
|
|
|
| 1549 |
|
| 1550 |
*Effects:* Behaves as an unformatted output function (as described
|
| 1551 |
above). After constructing a sentry object, inserts the character `c`,
|
| 1552 |
if possible.[^37]
|
| 1553 |
|
| 1554 |
+
Otherwise, calls `setstate(badbit)` (which may throw `ios_base::failure`
|
| 1555 |
+
[[iostate.flags]]).
|
| 1556 |
|
| 1557 |
*Returns:* `*this`.
|
| 1558 |
|
| 1559 |
``` cpp
|
| 1560 |
basic_ostream& write(const char_type* s, streamsize n);
|
|
|
|
| 1566 |
by `s`.[^38] Characters are inserted until either of the following
|
| 1567 |
occurs:
|
| 1568 |
|
| 1569 |
- `n` characters are inserted;
|
| 1570 |
- inserting in the output sequence fails (in which case the function
|
| 1571 |
+
calls `setstate(badbit)`, which may throw `ios_base::failure`
|
| 1572 |
+
[[iostate.flags]]).
|
| 1573 |
|
| 1574 |
*Returns:* `*this`.
|
| 1575 |
|
| 1576 |
``` cpp
|
| 1577 |
basic_ostream& flush();
|
|
|
|
| 1579 |
|
| 1580 |
*Effects:* Behaves as an unformatted output function (as described
|
| 1581 |
above). If `rdbuf()` is not a null pointer, constructs a sentry object.
|
| 1582 |
If this object returns `true` when converted to a value of type `bool`
|
| 1583 |
the function calls `rdbuf()->pubsync()`. If that function returns -1
|
| 1584 |
+
calls `setstate(badbit)` (which may throw `ios_base::failure`
|
| 1585 |
+
[[iostate.flags]]). Otherwise, if the sentry object returns `false`,
|
| 1586 |
+
does nothing.
|
| 1587 |
|
| 1588 |
*Returns:* `*this`.
|
| 1589 |
|
| 1590 |
+
#### Standard manipulators <a id="ostream.manip">[[ostream.manip]]</a>
|
| 1591 |
+
|
| 1592 |
+
Each instantiation of any of the function templates specified in this
|
| 1593 |
+
subclause is a designated addressable function [[namespace.std]].
|
| 1594 |
|
| 1595 |
``` cpp
|
| 1596 |
template<class charT, class traits>
|
| 1597 |
basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);
|
| 1598 |
```
|
|
|
|
| 1618 |
|
| 1619 |
*Effects:* Calls `os.flush()`.
|
| 1620 |
|
| 1621 |
*Returns:* `os`.
|
| 1622 |
|
| 1623 |
+
``` cpp
|
| 1624 |
+
template<class charT, class traits>
|
| 1625 |
+
basic_ostream<charT, traits>& emit_on_flush(basic_ostream<charT, traits>& os);
|
| 1626 |
+
```
|
| 1627 |
+
|
| 1628 |
+
*Effects:* If `os.rdbuf()` is a
|
| 1629 |
+
`basic_syncbuf<charT, traits, Allocator>*`, called `buf` for the purpose
|
| 1630 |
+
of exposition, calls `buf->set_emit_on_sync(true)`. Otherwise this
|
| 1631 |
+
manipulator has no effect.
|
| 1632 |
+
|
| 1633 |
+
[*Note 1*: To work around the issue that the `Allocator` template
|
| 1634 |
+
argument cannot be deduced, implementations can introduce an
|
| 1635 |
+
intermediate base class to `basic_syncbuf` that manages its
|
| 1636 |
+
`emit_on_sync` flag. — *end note*]
|
| 1637 |
+
|
| 1638 |
+
*Returns:* `os`.
|
| 1639 |
+
|
| 1640 |
+
``` cpp
|
| 1641 |
+
template<class charT, class traits>
|
| 1642 |
+
basic_ostream<charT, traits>& noemit_on_flush(basic_ostream<charT, traits>& os);
|
| 1643 |
+
```
|
| 1644 |
+
|
| 1645 |
+
*Effects:* If `os.rdbuf()` is a
|
| 1646 |
+
`basic_syncbuf<charT, traits, Allocator>*`, called `buf` for the purpose
|
| 1647 |
+
of exposition, calls `buf->set_emit_on_sync(false)`. Otherwise this
|
| 1648 |
+
manipulator has no effect.
|
| 1649 |
+
|
| 1650 |
+
*Returns:* `os`.
|
| 1651 |
+
|
| 1652 |
+
``` cpp
|
| 1653 |
+
template<class charT, class traits>
|
| 1654 |
+
basic_ostream<charT, traits>& flush_emit(basic_ostream<charT, traits>& os);
|
| 1655 |
+
```
|
| 1656 |
+
|
| 1657 |
+
*Effects:* Calls `os.flush()`. Then, if `os.rdbuf()` is a
|
| 1658 |
+
`basic_syncbuf<charT, traits, Allocator>*`, called `buf` for the purpose
|
| 1659 |
+
of exposition, calls `buf->emit()`.
|
| 1660 |
+
|
| 1661 |
+
*Returns:* `os`.
|
| 1662 |
+
|
| 1663 |
#### Rvalue stream insertion <a id="ostream.rvalue">[[ostream.rvalue]]</a>
|
| 1664 |
|
| 1665 |
``` cpp
|
| 1666 |
+
template<class Ostream, class T>
|
| 1667 |
+
Ostream&& operator<<(Ostream&& os, const T& x);
|
| 1668 |
```
|
| 1669 |
|
| 1670 |
+
*Constraints:* The expression `os << x` is well-formed when treated as
|
| 1671 |
+
an unevaluated operand and `Ostream` is publicly and unambiguously
|
| 1672 |
+
derived from `ios_base`.
|
| 1673 |
+
|
| 1674 |
*Effects:* As if by: `os << x;`
|
| 1675 |
|
| 1676 |
+
*Returns:* `std::move(os)`.
|
|
|
|
|
|
|
|
|
|
| 1677 |
|
| 1678 |
### Standard manipulators <a id="std.manip">[[std.manip]]</a>
|
| 1679 |
|
| 1680 |
The header `<iomanip>` defines several functions that support extractors
|
| 1681 |
and inserters that alter information maintained by class `ios_base` and
|
|
|
|
| 1697 |
// reset specified flags
|
| 1698 |
str.setf(ios_base::fmtflags(0), mask);
|
| 1699 |
}
|
| 1700 |
```
|
| 1701 |
|
| 1702 |
+
The expression `out << resetiosflags(mask)` has type
|
| 1703 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1704 |
+
`in >> resetiosflags(mask)` has type `basic_istream<charT, traits>&` and
|
| 1705 |
+
value `in`.
|
| 1706 |
|
| 1707 |
``` cpp
|
| 1708 |
unspecified setiosflags(ios_base::fmtflags mask);
|
| 1709 |
```
|
| 1710 |
|
|
|
|
| 1720 |
// set specified flags
|
| 1721 |
str.setf(mask);
|
| 1722 |
}
|
| 1723 |
```
|
| 1724 |
|
| 1725 |
+
The expression `out << setiosflags(mask)` has type
|
| 1726 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1727 |
+
`in >> setiosflags(mask)` has type `basic_istream<charT, traits>&` and
|
| 1728 |
+
value `in`.
|
| 1729 |
|
| 1730 |
``` cpp
|
| 1731 |
unspecified setbase(int base);
|
| 1732 |
```
|
| 1733 |
|
|
|
|
| 1746 |
base == 16 ? ios_base::hex :
|
| 1747 |
ios_base::fmtflags(0), ios_base::basefield);
|
| 1748 |
}
|
| 1749 |
```
|
| 1750 |
|
| 1751 |
+
The expression `out << setbase(base)` has type
|
| 1752 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1753 |
+
`in >> setbase(base)` has type `basic_istream<charT, traits>&` and value
|
| 1754 |
+
`in`.
|
| 1755 |
|
| 1756 |
``` cpp
|
| 1757 |
unspecified setfill(char_type c);
|
| 1758 |
```
|
| 1759 |
|
|
|
|
| 1768 |
// set fill character
|
| 1769 |
str.fill(c);
|
| 1770 |
}
|
| 1771 |
```
|
| 1772 |
|
| 1773 |
+
The expression `out << setfill(c)` has type
|
| 1774 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1775 |
|
| 1776 |
``` cpp
|
| 1777 |
unspecified setprecision(int n);
|
| 1778 |
```
|
|
|
|
| 1789 |
// set precision
|
| 1790 |
str.precision(n);
|
| 1791 |
}
|
| 1792 |
```
|
| 1793 |
|
| 1794 |
+
The expression `out << setprecision(n)` has type
|
| 1795 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1796 |
+
`in >> setprecision(n)` has type `basic_istream<charT, traits>&` and
|
| 1797 |
+
value `in`.
|
| 1798 |
|
| 1799 |
``` cpp
|
| 1800 |
unspecified setw(int n);
|
| 1801 |
```
|
| 1802 |
|
|
|
|
| 1812 |
// set width
|
| 1813 |
str.width(n);
|
| 1814 |
}
|
| 1815 |
```
|
| 1816 |
|
| 1817 |
+
The expression `out << setw(n)` has type `basic_ostream<charT, traits>&`
|
| 1818 |
+
and value `out`. The expression `in >> setw(n)` has type
|
| 1819 |
+
`basic_istream<charT, traits>&` and value `in`.
|
|
|
|
| 1820 |
|
| 1821 |
### Extended manipulators <a id="ext.manip">[[ext.manip]]</a>
|
| 1822 |
|
| 1823 |
The header `<iomanip>` defines several functions that support extractors
|
| 1824 |
and inserters that allow for the parsing and formatting of sequences and
|
|
|
|
| 1826 |
|
| 1827 |
``` cpp
|
| 1828 |
template<class moneyT> unspecified get_money(moneyT& mon, bool intl = false);
|
| 1829 |
```
|
| 1830 |
|
| 1831 |
+
*Mandates:* The type `moneyT` is either `long double` or a
|
| 1832 |
+
specialization of the `basic_string` template [[strings]].
|
| 1833 |
|
| 1834 |
*Effects:* The expression `in >> get_money(mon, intl)` described below
|
| 1835 |
+
behaves as a formatted input function [[istream.formatted.reqmts]].
|
| 1836 |
|
| 1837 |
*Returns:* An object of unspecified type such that if `in` is an object
|
| 1838 |
of type `basic_istream<charT, traits>` then the expression
|
| 1839 |
`in >> get_money(mon, intl)` behaves as if it called `f(in, mon, intl)`,
|
| 1840 |
where the function `f` is defined as:
|
|
|
|
| 1853 |
if (ios_base::goodbit != err)
|
| 1854 |
str.setstate(err);
|
| 1855 |
}
|
| 1856 |
```
|
| 1857 |
|
| 1858 |
+
The expression `in >> get_money(mon, intl)` has type
|
| 1859 |
`basic_istream<charT, traits>&` and value `in`.
|
| 1860 |
|
| 1861 |
``` cpp
|
| 1862 |
template<class moneyT> unspecified put_money(const moneyT& mon, bool intl = false);
|
| 1863 |
```
|
| 1864 |
|
| 1865 |
+
*Mandates:* The type `moneyT` is either `long double` or a
|
| 1866 |
+
specialization of the `basic_string` template [[strings]].
|
| 1867 |
|
| 1868 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1869 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1870 |
`out << put_money(mon, intl)` behaves as a formatted output
|
| 1871 |
+
function [[ostream.formatted.reqmts]] that calls `f(out, mon, intl)`,
|
| 1872 |
where the function `f` is defined as:
|
| 1873 |
|
| 1874 |
``` cpp
|
| 1875 |
template<class charT, class traits, class moneyT>
|
| 1876 |
void f(basic_ios<charT, traits>& str, const moneyT& mon, bool intl) {
|
|
|
|
| 1879 |
|
| 1880 |
const MoneyPut& mp = use_facet<MoneyPut>(str.getloc());
|
| 1881 |
const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon);
|
| 1882 |
|
| 1883 |
if (end.failed())
|
| 1884 |
+
str.setstate(ios_base::badbit);
|
| 1885 |
}
|
| 1886 |
```
|
| 1887 |
|
| 1888 |
+
The expression `out << put_money(mon, intl)` has type
|
| 1889 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1890 |
|
| 1891 |
``` cpp
|
| 1892 |
template<class charT> unspecified get_time(struct tm* tmb, const charT* fmt);
|
| 1893 |
```
|
| 1894 |
|
| 1895 |
+
*Preconditions:* The argument `tmb` is a valid pointer to an object of
|
| 1896 |
+
type `struct tm`, and \[`fmt`, `fmt + char_traits<charT>::length(fmt)`)
|
| 1897 |
+
is a valid range.
|
|
|
|
| 1898 |
|
| 1899 |
*Returns:* An object of unspecified type such that if `in` is an object
|
| 1900 |
of type `basic_istream<charT, traits>` then the expression
|
| 1901 |
`in >> get_time(tmb, fmt)` behaves as if it called `f(in, tmb, fmt)`,
|
| 1902 |
where the function `f` is defined as:
|
|
|
|
| 1916 |
if (err != ios_base::goodbit)
|
| 1917 |
str.setstate(err);
|
| 1918 |
}
|
| 1919 |
```
|
| 1920 |
|
| 1921 |
+
The expression `in >> get_time(tmb, fmt)` has type
|
| 1922 |
`basic_istream<charT, traits>&` and value `in`.
|
| 1923 |
|
| 1924 |
``` cpp
|
| 1925 |
template<class charT> unspecified put_time(const struct tm* tmb, const charT* fmt);
|
| 1926 |
```
|
| 1927 |
|
| 1928 |
+
*Preconditions:* The argument `tmb` is a valid pointer to an object of
|
| 1929 |
+
type `struct tm`, and \[`fmt`, `fmt + char_traits<charT>::length(fmt)`)
|
| 1930 |
+
is a valid range.
|
|
|
|
| 1931 |
|
| 1932 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1933 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1934 |
`out << put_time(tmb, fmt)` behaves as if it called `f(out, tmb, fmt)`,
|
| 1935 |
where the function `f` is defined as:
|
|
|
|
| 1947 |
if (end.failed())
|
| 1948 |
str.setstate(ios_base::badbit);
|
| 1949 |
}
|
| 1950 |
```
|
| 1951 |
|
| 1952 |
+
The expression `out << put_time(tmb, fmt)` has type
|
| 1953 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1954 |
|
| 1955 |
### Quoted manipulators <a id="quoted.manip">[[quoted.manip]]</a>
|
| 1956 |
|
| 1957 |
[*Note 1*: Quoted manipulators provide string insertion and extraction
|
|
|
|
| 1974 |
*Returns:* An object of unspecified type such that if `out` is an
|
| 1975 |
instance of `basic_ostream` with member type `char_type` the same as
|
| 1976 |
`charT` and with member type `traits_type`, which in the second and
|
| 1977 |
third forms is the same as `traits`, then the expression
|
| 1978 |
`out << quoted(s, delim, escape)` behaves as a formatted output
|
| 1979 |
+
function [[ostream.formatted.reqmts]] of `out`. This forms a character
|
| 1980 |
+
sequence `seq`, initially consisting of the following elements:
|
|
|
|
| 1981 |
|
| 1982 |
- `delim`.
|
| 1983 |
- Each character in `s`. If the character to be output is equal to
|
| 1984 |
`escape` or `delim`, as determined by `traits_type::eq`, first output
|
| 1985 |
`escape`.
|
|
|
|
| 1987 |
|
| 1988 |
Let `x` be the number of elements initially in `seq`. Then padding is
|
| 1989 |
determined for `seq` as described in [[ostream.formatted.reqmts]],
|
| 1990 |
`seq` is inserted as if by calling `out.rdbuf()->sputn(seq, n)`, where
|
| 1991 |
`n` is the larger of `out.width()` and `x`, and `out.width(0)` is
|
| 1992 |
+
called. The expression `out << quoted(s, delim, escape)` has type
|
| 1993 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1994 |
|
| 1995 |
``` cpp
|
| 1996 |
template<class charT, class traits, class Allocator>
|
| 1997 |
unspecified quoted(basic_string<charT, traits, Allocator>& s,
|
|
|
|
| 2002 |
|
| 2003 |
- If `in` is an instance of `basic_istream` with member types
|
| 2004 |
`char_type` and `traits_type` the same as `charT` and `traits`,
|
| 2005 |
respectively, then the expression `in >> quoted(s, delim, escape)`
|
| 2006 |
behaves as if it extracts the following characters from `in` using
|
| 2007 |
+
`operator>>(basic_istream<charT, traits>&, charT&)`
|
| 2008 |
+
[[istream.extractors]] which may throw `ios_base::failure`
|
| 2009 |
+
[[ios.failure]]:
|
| 2010 |
- If the first character extracted is equal to `delim`, as determined
|
| 2011 |
by `traits_type::eq`, then:
|
| 2012 |
- Turn off the `skipws` flag.
|
| 2013 |
- `s.clear()`
|
| 2014 |
- Until an unescaped `delim` character is reached or `!in`, extract
|
|
|
|
| 2022 |
`char_type` and `traits_type` the same as `charT` and `traits`,
|
| 2023 |
respectively, then the expression `out << quoted(s, delim, escape)`
|
| 2024 |
behaves as specified for the
|
| 2025 |
`const basic_string<charT, traits, Allocator>&` overload of the
|
| 2026 |
`quoted` function.
|
| 2027 |
+
- The expression `in >> quoted(s, delim, escape)` has type
|
| 2028 |
+
`basic_istream<charT, traits>&` and value `in`.
|
| 2029 |
+
- The expression `out << quoted(s, delim, escape)` has type
|
|
|
|
| 2030 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 2031 |
|