- tmp/tmp0hqgflvw/{from.md → to.md} +425 -416
tmp/tmp0hqgflvw/{from.md → to.md}
RENAMED
|
@@ -1,52 +1,55 @@
|
|
| 1 |
## Formatting and manipulators <a id="iostream.format">[[iostream.format]]</a>
|
| 2 |
|
| 3 |
-
###
|
| 4 |
-
|
| 5 |
-
\synopsis{Header \texttt{\<istream\>} synopsis}
|
| 6 |
|
| 7 |
``` cpp
|
| 8 |
namespace std {
|
| 9 |
template <class charT, class traits = char_traits<charT>>
|
| 10 |
class basic_istream;
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
template <class charT, class traits = char_traits<charT>>
|
| 15 |
class basic_iostream;
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
template <class charT, class traits>
|
| 20 |
basic_istream<charT, traits>& ws(basic_istream<charT, traits>& is);
|
| 21 |
|
| 22 |
template <class charT, class traits, class T>
|
| 23 |
-
basic_istream<charT, traits>&
|
| 24 |
-
operator>>(basic_istream<charT, traits>&& is, T& x);
|
| 25 |
}
|
| 26 |
```
|
| 27 |
|
|
|
|
|
|
|
| 28 |
``` cpp
|
| 29 |
namespace std {
|
| 30 |
template <class charT, class traits = char_traits<charT>>
|
| 31 |
class basic_ostream;
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
template <class charT, class traits>
|
| 36 |
basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);
|
| 37 |
template <class charT, class traits>
|
| 38 |
basic_ostream<charT, traits>& ends(basic_ostream<charT, traits>& os);
|
| 39 |
template <class charT, class traits>
|
| 40 |
basic_ostream<charT, traits>& flush(basic_ostream<charT, traits>& os);
|
| 41 |
|
| 42 |
template <class charT, class traits, class T>
|
| 43 |
-
basic_ostream<charT, traits>&
|
| 44 |
-
operator<<(basic_ostream<charT, traits>&& os, const T& x);
|
| 45 |
}
|
| 46 |
```
|
| 47 |
|
|
|
|
|
|
|
| 48 |
``` cpp
|
| 49 |
namespace std {
|
| 50 |
// types T1, T2, ... are unspecified implementation types
|
| 51 |
T1 resetiosflags(ios_base::fmtflags mask);
|
| 52 |
T2 setiosflags (ios_base::fmtflags mask);
|
|
@@ -62,15 +65,19 @@ namespace std {
|
|
| 62 |
template <class charT>
|
| 63 |
T11 quoted(const charT* s, charT delim = charT('"'), charT escape = charT('\\'));
|
| 64 |
|
| 65 |
template <class charT, class traits, class Allocator>
|
| 66 |
T12 quoted(const basic_string<charT, traits, Allocator>& s,
|
| 67 |
-
|
| 68 |
|
| 69 |
template <class charT, class traits, class Allocator>
|
| 70 |
T13 quoted(basic_string<charT, traits, Allocator>& s,
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|
| 73 |
```
|
| 74 |
|
| 75 |
### Input streams <a id="input.streams">[[input.streams]]</a>
|
| 76 |
|
|
@@ -84,30 +91,30 @@ extracts from stream rvalues.
|
|
| 84 |
namespace std {
|
| 85 |
template <class charT, class traits = char_traits<charT>>
|
| 86 |
class basic_istream : virtual public basic_ios<charT, traits> {
|
| 87 |
public:
|
| 88 |
// types (inherited from basic_ios ([ios])):
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
-
// [istream.cons]
|
| 96 |
explicit basic_istream(basic_streambuf<charT, traits>* sb);
|
| 97 |
virtual ~basic_istream();
|
| 98 |
|
| 99 |
-
// [istream::sentry]
|
| 100 |
class sentry;
|
| 101 |
|
| 102 |
-
// [istream.formatted]
|
| 103 |
-
basic_istream<charT,traits>&
|
| 104 |
-
basic_istream<charT,traits>& (*pf)(basic_istream<charT,traits>&));
|
| 105 |
-
basic_istream<charT,traits>&
|
| 106 |
-
|
| 107 |
-
basic_istream<charT,traits>&
|
| 108 |
-
ios_base& (*pf)(ios_base&));
|
| 109 |
|
| 110 |
basic_istream<charT, traits>& operator>>(bool& n);
|
| 111 |
basic_istream<charT, traits>& operator>>(short& n);
|
| 112 |
basic_istream<charT, traits>& operator>>(unsigned short& n);
|
| 113 |
basic_istream<charT, traits>& operator>>(int& n);
|
|
@@ -119,30 +126,25 @@ namespace std {
|
|
| 119 |
basic_istream<charT, traits>& operator>>(float& f);
|
| 120 |
basic_istream<charT, traits>& operator>>(double& f);
|
| 121 |
basic_istream<charT, traits>& operator>>(long double& f);
|
| 122 |
|
| 123 |
basic_istream<charT, traits>& operator>>(void*& p);
|
| 124 |
-
basic_istream<charT,traits>& operator>>(
|
| 125 |
-
basic_streambuf<char_type,traits>* sb);
|
| 126 |
|
| 127 |
-
// [istream.unformatted]
|
| 128 |
streamsize gcount() const;
|
| 129 |
int_type get();
|
| 130 |
basic_istream<charT, traits>& get(char_type& c);
|
| 131 |
basic_istream<charT, traits>& get(char_type* s, streamsize n);
|
| 132 |
-
basic_istream<charT,traits>& get(char_type* s, streamsize n,
|
| 133 |
-
char_type delim);
|
| 134 |
basic_istream<charT, traits>& get(basic_streambuf<char_type, traits>& sb);
|
| 135 |
-
basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb,
|
| 136 |
-
char_type delim);
|
| 137 |
|
| 138 |
basic_istream<charT, traits>& getline(char_type* s, streamsize n);
|
| 139 |
-
basic_istream<charT,traits>& getline(char_type* s, streamsize n,
|
| 140 |
-
char_type delim);
|
| 141 |
|
| 142 |
-
basic_istream<charT,traits>& ignore(
|
| 143 |
-
streamsize n = 1, int_type delim = traits::eof());
|
| 144 |
int_type peek();
|
| 145 |
basic_istream<charT, traits>& read (char_type* s, streamsize n);
|
| 146 |
streamsize readsome(char_type* s, streamsize n);
|
| 147 |
|
| 148 |
basic_istream<charT, traits>& putback(char_type c);
|
|
@@ -152,45 +154,40 @@ namespace std {
|
|
| 152 |
pos_type tellg();
|
| 153 |
basic_istream<charT, traits>& seekg(pos_type);
|
| 154 |
basic_istream<charT, traits>& seekg(off_type, ios_base::seekdir);
|
| 155 |
|
| 156 |
protected:
|
|
|
|
| 157 |
basic_istream(const basic_istream& rhs) = delete;
|
| 158 |
basic_istream(basic_istream&& rhs);
|
| 159 |
|
| 160 |
-
// [istream.assign]
|
| 161 |
basic_istream& operator=(const basic_istream& rhs) = delete;
|
| 162 |
basic_istream& operator=(basic_istream&& rhs);
|
| 163 |
void swap(basic_istream& rhs);
|
| 164 |
};
|
| 165 |
|
| 166 |
-
// [istream
|
| 167 |
template<class charT, class traits>
|
| 168 |
-
basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&,
|
| 169 |
-
charT&);
|
| 170 |
template<class traits>
|
| 171 |
-
basic_istream<char,traits>& operator>>(basic_istream<char,traits>&,
|
| 172 |
-
unsigned char&);
|
| 173 |
template<class traits>
|
| 174 |
-
basic_istream<char,traits>& operator>>(basic_istream<char,traits>&,
|
| 175 |
-
signed char&);
|
| 176 |
|
| 177 |
template<class charT, class traits>
|
| 178 |
-
basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&,
|
| 179 |
-
charT*);
|
| 180 |
template<class traits>
|
| 181 |
-
basic_istream<char,traits>& operator>>(basic_istream<char,traits>&,
|
| 182 |
-
unsigned char*);
|
| 183 |
template<class traits>
|
| 184 |
-
basic_istream<char,traits>& operator>>(basic_istream<char,traits>&,
|
| 185 |
-
signed char*);
|
| 186 |
}
|
| 187 |
```
|
| 188 |
|
| 189 |
-
The class `basic_istream` defines a number of member function
|
| 190 |
-
that assist in reading and interpreting input from sequences
|
| 191 |
-
by a stream buffer.
|
| 192 |
|
| 193 |
Two groups of member function signatures share common properties: the
|
| 194 |
*formatted input functions* (or *extractors*) and the *unformatted input
|
| 195 |
functions.* Both groups of input functions are described as if they
|
| 196 |
obtain (or *extract*) input *characters* by calling `rdbuf()->sbumpc()`
|
|
@@ -212,15 +209,15 @@ failure indication.
|
|
| 212 |
|
| 213 |
``` cpp
|
| 214 |
explicit basic_istream(basic_streambuf<charT, traits>* sb);
|
| 215 |
```
|
| 216 |
|
| 217 |
-
*Effects:* Constructs an object of class `basic_istream`,
|
| 218 |
-
|
| 219 |
`basic_ios::init(sb)` ([[basic.ios.cons]]).
|
| 220 |
|
| 221 |
-
`gcount() == 0`
|
| 222 |
|
| 223 |
``` cpp
|
| 224 |
basic_istream(basic_istream&& rhs);
|
| 225 |
```
|
| 226 |
|
|
@@ -241,11 +238,11 @@ virtual ~basic_istream();
|
|
| 241 |
|
| 242 |
``` cpp
|
| 243 |
basic_istream& operator=(basic_istream&& rhs);
|
| 244 |
```
|
| 245 |
|
| 246 |
-
*Effects:* `swap(rhs)
|
| 247 |
|
| 248 |
*Returns:* `*this`.
|
| 249 |
|
| 250 |
``` cpp
|
| 251 |
void swap(basic_istream& rhs);
|
|
@@ -258,11 +255,11 @@ values returned by `gcount()` and `rhs.gcount()`.
|
|
| 258 |
|
| 259 |
``` cpp
|
| 260 |
namespace std {
|
| 261 |
template <class charT, class traits = char_traits<charT>>
|
| 262 |
class basic_istream<charT, traits>::sentry {
|
| 263 |
-
|
| 264 |
bool ok_; // exposition only
|
| 265 |
public:
|
| 266 |
explicit sentry(basic_istream<charT, traits>& is, bool noskipws = false);
|
| 267 |
~sentry();
|
| 268 |
explicit operator bool() const { return ok_; }
|
|
@@ -285,19 +282,23 @@ Otherwise, prepares for formatted or unformatted input. First, if
|
|
| 285 |
to synchronize the output sequence with any associated external C
|
| 286 |
stream. Except that this call can be suppressed if the put area of
|
| 287 |
`is.tie()` is empty. Further an implementation is allowed to defer the
|
| 288 |
call to `flush` until a call of `is.rdbuf()->underflow()` occurs. If no
|
| 289 |
such call occurs before the `sentry` object is destroyed, the call to
|
| 290 |
-
`flush` may be eliminated entirely.[^
|
| 291 |
`is.flags() & ios_base::skipws` is nonzero, the function extracts and
|
| 292 |
discards each character as long as the next available input character
|
| 293 |
`c` is a whitespace character. If `is.rdbuf()->sbumpc()` or
|
| 294 |
`is.rdbuf()->sgetc()` returns `traits::eof()`, the function calls
|
| 295 |
`setstate(failbit | eofbit)` (which may throw `ios_base::failure`).
|
| 296 |
|
| 297 |
*Remarks:* The constructor
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
uses the currently imbued locale in `is`, to determine whether the next
|
| 300 |
input character is whitespace or not.
|
| 301 |
|
| 302 |
To decide if the character `c` is a whitespace character, the
|
| 303 |
constructor performs as if it executes the following code fragment:
|
|
@@ -309,11 +310,11 @@ if (ctype.is(ctype.space,c)!=0)
|
|
| 309 |
```
|
| 310 |
|
| 311 |
If, after any preparation is completed, `is.good()` is `true`,
|
| 312 |
`ok_ != false` otherwise, `ok_ == false`. During preparation, the
|
| 313 |
constructor may call `setstate(failbit)` (which may throw
|
| 314 |
-
`ios_base::failure` ([[iostate.flags]]))[^
|
| 315 |
|
| 316 |
``` cpp
|
| 317 |
~sentry();
|
| 318 |
```
|
| 319 |
|
|
@@ -331,11 +332,11 @@ explicit operator bool() const;
|
|
| 331 |
|
| 332 |
Each formatted input function begins execution by constructing an object
|
| 333 |
of class `sentry` with the `noskipws` (second) argument `false`. If the
|
| 334 |
`sentry` object returns `true`, when converted to a value of type
|
| 335 |
`bool`, the function endeavors to obtain the requested input. If an
|
| 336 |
-
exception is thrown during input then `ios::badbit` is turned on[^
|
| 337 |
`*this`’s error state. If `(exceptions()&badbit) != 0` then the
|
| 338 |
exception is rethrown. In any case, the formatted input function
|
| 339 |
destroys the `sentry` object. If no exception has been thrown, it
|
| 340 |
returns `*this`.
|
| 341 |
|
|
@@ -361,32 +362,36 @@ stream data. These extractors behave as formatted input functions (as
|
|
| 361 |
described in [[istream.formatted.reqmts]]). After a sentry object is
|
| 362 |
constructed, the conversion occurs as if performed by the following code
|
| 363 |
fragment:
|
| 364 |
|
| 365 |
``` cpp
|
| 366 |
-
|
| 367 |
iostate err = iostate::goodbit;
|
| 368 |
use_facet<numget>(loc).get(*this, 0, *this, err, val);
|
| 369 |
setstate(err);
|
| 370 |
```
|
| 371 |
|
| 372 |
In the above fragment, `loc` stands for the private member of the
|
| 373 |
-
`basic_ios` class.
|
|
|
|
|
|
|
| 374 |
`istreambuf_iterator` class which is an iterator pointed to an input
|
| 375 |
-
stream. It bypasses istreams and uses streambufs
|
| 376 |
-
|
| 377 |
-
|
|
|
|
|
|
|
| 378 |
|
| 379 |
``` cpp
|
| 380 |
operator>>(short& val);
|
| 381 |
```
|
| 382 |
|
| 383 |
The conversion occurs as if performed by the following code fragment
|
| 384 |
(using the same notation as for the preceding code fragment):
|
| 385 |
|
| 386 |
``` cpp
|
| 387 |
-
|
| 388 |
iostate err = ios_base::goodbit;
|
| 389 |
long lval;
|
| 390 |
use_facet<numget>(loc).get(*this, 0, *this, err, lval);
|
| 391 |
if (lval < numeric_limits<short>::min()) {
|
| 392 |
err |= ios_base::failbit;
|
|
@@ -405,11 +410,11 @@ operator>>(int& val);
|
|
| 405 |
|
| 406 |
The conversion occurs as if performed by the following code fragment
|
| 407 |
(using the same notation as for the preceding code fragment):
|
| 408 |
|
| 409 |
``` cpp
|
| 410 |
-
|
| 411 |
iostate err = ios_base::goodbit;
|
| 412 |
long lval;
|
| 413 |
use_facet<numget>(loc).get(*this, 0, *this, err, lval);
|
| 414 |
if (lval < numeric_limits<int>::min()) {
|
| 415 |
err |= ios_base::failbit;
|
|
@@ -420,54 +425,50 @@ if (lval < numeric_limits<int>::min()) {
|
|
| 420 |
} else
|
| 421 |
val = static_cast<int>(lval);
|
| 422 |
setstate(err);
|
| 423 |
```
|
| 424 |
|
| 425 |
-
##### `basic_istream::operator>>` <a id="istream
|
| 426 |
|
| 427 |
``` cpp
|
| 428 |
-
basic_istream<charT,traits>&
|
| 429 |
-
|
| 430 |
```
|
| 431 |
|
| 432 |
*Effects:* None. This extractor does not behave as a formatted input
|
| 433 |
-
function (as described in [[istream.formatted.reqmts]]
|
| 434 |
|
| 435 |
-
*Returns:* `pf(*this)`.[^
|
| 436 |
|
| 437 |
``` cpp
|
| 438 |
-
basic_istream<charT,traits>&
|
| 439 |
-
|
| 440 |
```
|
| 441 |
|
| 442 |
*Effects:* Calls `pf(*this)`. This extractor does not behave as a
|
| 443 |
formatted input function (as described
|
| 444 |
in [[istream.formatted.reqmts]]).
|
| 445 |
|
| 446 |
*Returns:* `*this`.
|
| 447 |
|
| 448 |
``` cpp
|
| 449 |
-
basic_istream<charT,traits>& operator>>
|
| 450 |
-
(ios_base& (*pf)(ios_base&));
|
| 451 |
```
|
| 452 |
|
| 453 |
-
*Effects:* Calls `pf(*this)`.[^
|
| 454 |
formatted input function (as described
|
| 455 |
in [[istream.formatted.reqmts]]).
|
| 456 |
|
| 457 |
*Returns:* `*this`.
|
| 458 |
|
| 459 |
``` cpp
|
| 460 |
template<class charT, class traits>
|
| 461 |
-
basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>& in,
|
| 462 |
-
charT* s);
|
| 463 |
template<class traits>
|
| 464 |
-
basic_istream<char,traits>& operator>>(basic_istream<char,traits>& in,
|
| 465 |
-
unsigned char* s);
|
| 466 |
template<class traits>
|
| 467 |
-
basic_istream<char,traits>& operator>>(basic_istream<char,traits>& in,
|
| 468 |
-
signed char* s);
|
| 469 |
```
|
| 470 |
|
| 471 |
*Effects:* Behaves like a formatted input member (as described
|
| 472 |
in [[istream.formatted.reqmts]]) of `in`. After a `sentry` object is
|
| 473 |
constructed, `operator>>` extracts characters and stores them into
|
|
@@ -479,12 +480,12 @@ 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;
|
| 484 |
-
- `ct
|
| 485 |
-
`
|
| 486 |
|
| 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 |
|
|
@@ -493,38 +494,33 @@ which may throw `ios_base::failure` ([[iostate.flags]]).
|
|
| 493 |
|
| 494 |
*Returns:* `in`.
|
| 495 |
|
| 496 |
``` cpp
|
| 497 |
template<class charT, class traits>
|
| 498 |
-
basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>& in,
|
| 499 |
-
charT& c);
|
| 500 |
template<class traits>
|
| 501 |
-
basic_istream<char,traits>& operator>>(basic_istream<char,traits>& in,
|
| 502 |
-
unsigned char& c);
|
| 503 |
template<class traits>
|
| 504 |
-
basic_istream<char,traits>& operator>>(basic_istream<char,traits>& in,
|
| 505 |
-
signed char& c);
|
| 506 |
```
|
| 507 |
|
| 508 |
*Effects:* Behaves like a formatted input member (as described
|
| 509 |
in [[istream.formatted.reqmts]]) of `in`. After a `sentry` object is
|
| 510 |
constructed a character is extracted from `in`, if one is available, and
|
| 511 |
stored in `c`. Otherwise, the function calls `in.setstate(failbit)`.
|
| 512 |
|
| 513 |
*Returns:* `in`.
|
| 514 |
|
| 515 |
``` cpp
|
| 516 |
-
basic_istream<charT,traits>& operator>>
|
| 517 |
-
(basic_streambuf<charT,traits>* sb);
|
| 518 |
```
|
| 519 |
|
| 520 |
-
*Effects:* Behaves as an unformatted input function
|
| 521 |
-
|
| 522 |
-
`
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
output sequence controlled by `sb`. Characters are extracted and
|
| 526 |
inserted until any of the following occurs:
|
| 527 |
|
| 528 |
- end-of-file occurs on the input sequence;
|
| 529 |
- inserting in the output sequence fails (in which case the character to
|
| 530 |
be inserted is not extracted);
|
|
@@ -544,18 +540,18 @@ rethrown.
|
|
| 544 |
Each unformatted input function begins execution by constructing an
|
| 545 |
object of class `sentry` with the default argument `noskipws` (second)
|
| 546 |
argument `true`. If the `sentry` object returns `true`, when converted
|
| 547 |
to a value of type `bool`, the function endeavors to obtain the
|
| 548 |
requested input. Otherwise, if the sentry constructor exits by throwing
|
| 549 |
-
an exception or if the sentry object returns false, when converted to
|
| 550 |
-
value of type `bool`, the function returns without attempting to
|
| 551 |
-
any input. In either case the number of extracted characters is
|
| 552 |
-
0; unformatted input functions taking a character array of
|
| 553 |
-
as an argument shall also store a null character (using
|
| 554 |
-
the first location of the array. If an exception is thrown
|
| 555 |
-
then `ios::badbit` is turned on[^
|
| 556 |
-
(Exceptions thrown from `basic_ios<>::clear()` are not caught or
|
| 557 |
rethrown.) If `(exceptions()&badbit) != 0` then the exception is
|
| 558 |
rethrown. It also counts the number of characters extracted. If no
|
| 559 |
exception has been thrown it ends by storing the count in a member
|
| 560 |
object and returning the value specified. In any event the `sentry`
|
| 561 |
object is destroyed before leaving the unformatted input function.
|
|
@@ -563,49 +559,47 @@ object is destroyed before leaving the unformatted input function.
|
|
| 563 |
``` cpp
|
| 564 |
streamsize gcount() const;
|
| 565 |
```
|
| 566 |
|
| 567 |
*Effects:* None. This member function does not behave as an unformatted
|
| 568 |
-
input function (as described
|
| 569 |
|
| 570 |
*Returns:* The number of characters extracted by the last unformatted
|
| 571 |
input member function called for the object.
|
| 572 |
|
| 573 |
``` cpp
|
| 574 |
int_type get();
|
| 575 |
```
|
| 576 |
|
| 577 |
*Effects:* Behaves as an unformatted input function (as described
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
`ios_base::failure` ([[iostate.flags]]),
|
| 582 |
|
| 583 |
*Returns:* `c` if available, otherwise `traits::eof()`.
|
| 584 |
|
| 585 |
``` cpp
|
| 586 |
basic_istream<charT, traits>& get(char_type& c);
|
| 587 |
```
|
| 588 |
|
| 589 |
*Effects:* Behaves as an unformatted input function (as described
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
`
|
| 593 |
-
|
| 594 |
|
| 595 |
*Returns:* `*this`.
|
| 596 |
|
| 597 |
``` cpp
|
| 598 |
-
basic_istream<charT,traits>& get(char_type* s, streamsize n,
|
| 599 |
-
char_type delim );
|
| 600 |
```
|
| 601 |
|
| 602 |
*Effects:* Behaves as an unformatted input function (as described
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
|
| 608 |
- `n` is less than one or `n - 1` characters are stored;
|
| 609 |
- end-of-file occurs on the input sequence (in which case the function
|
| 610 |
calls `setstate(eofbit)`);
|
| 611 |
- `traits::eq(c, delim)` for the next available input character `c` (in
|
|
@@ -620,24 +614,22 @@ next successive location of the array.
|
|
| 620 |
|
| 621 |
``` cpp
|
| 622 |
basic_istream<charT, traits>& get(char_type* s, streamsize n);
|
| 623 |
```
|
| 624 |
|
| 625 |
-
*Effects:* Calls `get(s,n,widen(’\n’))`
|
| 626 |
|
| 627 |
*Returns:* Value returned by the call.
|
| 628 |
|
| 629 |
``` cpp
|
| 630 |
-
basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb,
|
| 631 |
-
char_type delim );
|
| 632 |
```
|
| 633 |
|
| 634 |
*Effects:* Behaves as an unformatted input function (as described
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
the following occurs:
|
| 639 |
|
| 640 |
- end-of-file occurs on the input sequence;
|
| 641 |
- inserting in the output sequence fails (in which case the character to
|
| 642 |
be inserted is not extracted);
|
| 643 |
- `traits::eq(c, delim)` for the next available input character `c` (in
|
|
@@ -652,44 +644,45 @@ which may throw `ios_base::failure` ([[iostate.flags]]).
|
|
| 652 |
|
| 653 |
``` cpp
|
| 654 |
basic_istream<charT, traits>& get(basic_streambuf<char_type, traits>& sb);
|
| 655 |
```
|
| 656 |
|
| 657 |
-
*Effects:* Calls `get(sb, widen(’\n’))`
|
| 658 |
|
| 659 |
*Returns:* Value returned by the call.
|
| 660 |
|
| 661 |
``` cpp
|
| 662 |
-
basic_istream<charT,traits>& getline(char_type* s, streamsize n,
|
| 663 |
-
char_type delim);
|
| 664 |
```
|
| 665 |
|
| 666 |
*Effects:* Behaves as an unformatted input function (as described
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
|
| 672 |
1. end-of-file occurs on the input sequence (in which case the function
|
| 673 |
calls `setstate(eofbit)`);
|
| 674 |
2. `traits::eq(c, delim)` for the next available input character `c`
|
| 675 |
(in which case the input character is extracted but not
|
| 676 |
-
stored);[^
|
| 677 |
3. `n` is less than one or `n - 1` characters are stored (in which case
|
| 678 |
the function calls `setstate(failbit)`).
|
| 679 |
|
| 680 |
-
These conditions are tested in the order shown.[^
|
| 681 |
|
| 682 |
If the function extracts no characters, it calls `setstate(failbit)`
|
| 683 |
-
(which may throw `ios_base::failure` ([[iostate.flags]])).[^
|
| 684 |
|
| 685 |
In any case, if `n` is greater than zero, it then stores a null
|
| 686 |
character (using `charT()`) into the next successive location of the
|
| 687 |
array.
|
| 688 |
|
| 689 |
*Returns:* `*this`.
|
| 690 |
|
|
|
|
|
|
|
| 691 |
``` cpp
|
| 692 |
#include <iostream>
|
| 693 |
|
| 694 |
int main() {
|
| 695 |
using namespace std;
|
|
@@ -711,27 +704,28 @@ int main() {
|
|
| 711 |
cout << " (" << count << " chars): " << buffer << endl;
|
| 712 |
}
|
| 713 |
}
|
| 714 |
```
|
| 715 |
|
|
|
|
|
|
|
| 716 |
``` cpp
|
| 717 |
basic_istream<charT, traits>& getline(char_type* s, streamsize n);
|
| 718 |
```
|
| 719 |
|
| 720 |
*Returns:* `getline(s, n, widen(’\n’))`
|
| 721 |
|
| 722 |
``` cpp
|
| 723 |
-
basic_istream<charT,traits>&
|
| 724 |
-
ignore(streamsize n = 1, int_type delim = traits::eof());
|
| 725 |
```
|
| 726 |
|
| 727 |
*Effects:* Behaves as an unformatted input function (as described
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
|
| 732 |
-
- `n != numeric_limits<streamsize>::max()` ([[limits]]) and `n`
|
| 733 |
characters have been extracted so far
|
| 734 |
- end-of-file occurs on the input sequence (in which case the function
|
| 735 |
calls `setstate(eofbit)`, which may throw
|
| 736 |
`ios_base::failure` ([[iostate.flags]]));
|
| 737 |
- `traits::eq_int_type(traits::to_int_type(c), delim)` for the next
|
|
@@ -745,27 +739,26 @@ until any of the following occurs:
|
|
| 745 |
``` cpp
|
| 746 |
int_type peek();
|
| 747 |
```
|
| 748 |
|
| 749 |
*Effects:* Behaves as an unformatted input function (as described
|
| 750 |
-
|
| 751 |
-
|
| 752 |
|
| 753 |
*Returns:* `traits::eof()` if `good()` is `false`. Otherwise, returns
|
| 754 |
`rdbuf()->sgetc()`.
|
| 755 |
|
| 756 |
``` cpp
|
| 757 |
basic_istream<charT, traits>& read(char_type* s, streamsize n);
|
| 758 |
```
|
| 759 |
|
| 760 |
*Effects:* Behaves as an unformatted input function (as described
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
following occurs:
|
| 767 |
|
| 768 |
- `n` characters are stored;
|
| 769 |
- end-of-file occurs on the input sequence (in which case the function
|
| 770 |
calls `setstate(failbit | eofbit)`, which may throw
|
| 771 |
`ios_base::failure` ([[iostate.flags]])).
|
|
@@ -775,17 +768,16 @@ following occurs:
|
|
| 775 |
``` cpp
|
| 776 |
streamsize readsome(char_type* s, streamsize n);
|
| 777 |
```
|
| 778 |
|
| 779 |
*Effects:* Behaves as an unformatted input function (as described
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
characters;
|
| 787 |
|
| 788 |
- If `rdbuf()->in_avail() == 0`, extracts no characters
|
| 789 |
- If `rdbuf()->in_avail() > 0`, extracts `min(rdbuf()->in_avail(), n))`.
|
| 790 |
|
| 791 |
*Returns:* The number of characters extracted.
|
|
@@ -793,86 +785,87 @@ characters;
|
|
| 793 |
``` cpp
|
| 794 |
basic_istream<charT, traits>& putback(char_type c);
|
| 795 |
```
|
| 796 |
|
| 797 |
*Effects:* Behaves as an unformatted input function (as described
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
|
|
|
| 806 |
|
| 807 |
*Returns:* `*this`.
|
| 808 |
|
| 809 |
``` cpp
|
| 810 |
basic_istream<charT, traits>& unget();
|
| 811 |
```
|
| 812 |
|
| 813 |
*Effects:* Behaves as an unformatted input function (as described
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
|
|
|
| 822 |
|
| 823 |
*Returns:* `*this`.
|
| 824 |
|
| 825 |
``` cpp
|
| 826 |
int sync();
|
| 827 |
```
|
| 828 |
|
| 829 |
*Effects:* Behaves as an unformatted input function (as described
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
`setstate(badbit)` (which may throw
|
| 836 |
`ios_base::failure` ([[iostate.flags]]), and returns `-1`. Otherwise,
|
| 837 |
returns zero.
|
| 838 |
|
| 839 |
``` cpp
|
| 840 |
pos_type tellg();
|
| 841 |
```
|
| 842 |
|
| 843 |
*Effects:* Behaves as an unformatted input function (as described
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
|
| 848 |
*Returns:* After constructing a sentry object, if `fail() != false`,
|
| 849 |
returns `pos_type(-1)` to indicate failure. Otherwise, returns
|
| 850 |
`rdbuf()->pubseekoff(0, cur, in)`.
|
| 851 |
|
| 852 |
``` cpp
|
| 853 |
basic_istream<charT, traits>& seekg(pos_type pos);
|
| 854 |
```
|
| 855 |
|
| 856 |
*Effects:* Behaves as an unformatted input function (as described
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
`ios_base::failure`).
|
| 864 |
|
| 865 |
*Returns:* `*this`.
|
| 866 |
|
| 867 |
``` cpp
|
| 868 |
basic_istream<charT, traits>& seekg(off_type off, ios_base::seekdir dir);
|
| 869 |
```
|
| 870 |
|
| 871 |
*Effects:* Behaves as an unformatted input function (as described
|
| 872 |
-
|
| 873 |
-
the number of characters extracted and does not affect the value
|
| 874 |
returned by subsequent calls to `gcount()`. After constructing a sentry
|
| 875 |
object, if `fail() != true`, executes
|
| 876 |
`rdbuf()->pubseekoff(off, dir, ios_base::in)`. In case of failure, the
|
| 877 |
function calls `setstate(failbit)` (which may throw
|
| 878 |
`ios_base::failure`).
|
|
@@ -880,77 +873,94 @@ function calls `setstate(failbit)` (which may throw
|
|
| 880 |
*Returns:* `*this`.
|
| 881 |
|
| 882 |
#### Standard `basic_istream` manipulators <a id="istream.manip">[[istream.manip]]</a>
|
| 883 |
|
| 884 |
``` cpp
|
| 885 |
-
namespace std {
|
| 886 |
template <class charT, class traits>
|
| 887 |
basic_istream<charT, traits>& ws(basic_istream<charT, traits>& is);
|
| 888 |
-
}
|
| 889 |
```
|
| 890 |
|
| 891 |
-
*Effects:* Behaves as an unformatted input function
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
Whitespace characters are distinguished with the same criterion as used
|
| 898 |
by `sentry::sentry` ([[istream::sentry]]). If `ws` stops extracting
|
| 899 |
characters because there are no more available it sets `eofbit`, but not
|
| 900 |
`failbit`.
|
| 901 |
|
| 902 |
*Returns:* `is`.
|
| 903 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 904 |
#### Class template `basic_iostream` <a id="iostreamclass">[[iostreamclass]]</a>
|
| 905 |
|
| 906 |
``` cpp
|
| 907 |
namespace std {
|
| 908 |
template <class charT, class traits = char_traits<charT>>
|
| 909 |
-
class basic_iostream
|
| 910 |
-
public basic_istream<charT,traits>,
|
| 911 |
public basic_ostream<charT, traits> {
|
| 912 |
public:
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
typedef traits traits_type;
|
| 919 |
|
| 920 |
-
// constructor
|
| 921 |
explicit basic_iostream(basic_streambuf<charT, traits>* sb);
|
|
|
|
|
|
|
| 922 |
virtual ~basic_iostream();
|
| 923 |
|
| 924 |
protected:
|
|
|
|
| 925 |
basic_iostream(const basic_iostream& rhs) = delete;
|
| 926 |
basic_iostream(basic_iostream&& rhs);
|
| 927 |
|
| 928 |
-
// assign
|
| 929 |
basic_iostream& operator=(const basic_iostream& rhs) = delete;
|
| 930 |
basic_iostream& operator=(basic_iostream&& rhs);
|
| 931 |
void swap(basic_iostream& rhs);
|
| 932 |
};
|
| 933 |
}
|
| 934 |
```
|
| 935 |
|
| 936 |
-
The class `basic_iostream` inherits a number of functions that
|
| 937 |
-
reading input and writing output to sequences controlled by a
|
| 938 |
-
buffer.
|
| 939 |
|
| 940 |
##### `basic_iostream` constructors <a id="iostream.cons">[[iostream.cons]]</a>
|
| 941 |
|
| 942 |
``` cpp
|
| 943 |
explicit basic_iostream(basic_streambuf<charT, traits>* sb);
|
| 944 |
```
|
| 945 |
|
| 946 |
-
*Effects:* Constructs an object of class `basic_iostream`,
|
| 947 |
-
|
| 948 |
`basic_istream<charT, traits>(sb)` ([[istream]]) and
|
| 949 |
-
`basic_ostream<charT,traits>(sb)`
|
| 950 |
|
| 951 |
-
`rdbuf()==sb` and `gcount()==0`.
|
| 952 |
|
| 953 |
``` cpp
|
| 954 |
basic_iostream(basic_iostream&& rhs);
|
| 955 |
```
|
| 956 |
|
|
@@ -971,30 +981,18 @@ virtual ~basic_iostream();
|
|
| 971 |
|
| 972 |
``` cpp
|
| 973 |
basic_iostream& operator=(basic_iostream&& rhs);
|
| 974 |
```
|
| 975 |
|
| 976 |
-
*Effects:* `swap(rhs)`.
|
| 977 |
|
| 978 |
``` cpp
|
| 979 |
void swap(basic_iostream& rhs);
|
| 980 |
```
|
| 981 |
|
| 982 |
*Effects:* Calls `basic_istream<charT, traits>::swap(rhs)`.
|
| 983 |
|
| 984 |
-
#### Rvalue stream extraction <a id="istream.rvalue">[[istream.rvalue]]</a>
|
| 985 |
-
|
| 986 |
-
``` cpp
|
| 987 |
-
template <class charT, class traits, class T>
|
| 988 |
-
basic_istream<charT, traits>&
|
| 989 |
-
operator>>(basic_istream<charT, traits>&& is, T& x);
|
| 990 |
-
```
|
| 991 |
-
|
| 992 |
-
*Effects:* `is >>x`
|
| 993 |
-
|
| 994 |
-
*Returns:* `is`
|
| 995 |
-
|
| 996 |
### Output streams <a id="output.streams">[[output.streams]]</a>
|
| 997 |
|
| 998 |
The header `<ostream>` defines a type and several function signatures
|
| 999 |
that control output to a stream buffer along with a function template
|
| 1000 |
that inserts into stream rvalues.
|
|
@@ -1005,30 +1003,30 @@ that inserts into stream rvalues.
|
|
| 1005 |
namespace std {
|
| 1006 |
template <class charT, class traits = char_traits<charT>>
|
| 1007 |
class basic_ostream : virtual public basic_ios<charT, traits> {
|
| 1008 |
public:
|
| 1009 |
// types (inherited from basic_ios ([ios])):
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
|
| 1016 |
-
// [ostream.cons]
|
| 1017 |
explicit basic_ostream(basic_streambuf<char_type, traits>* sb);
|
| 1018 |
virtual ~basic_ostream();
|
| 1019 |
|
| 1020 |
-
// [ostream::sentry]
|
| 1021 |
class sentry;
|
| 1022 |
|
| 1023 |
-
// [ostream.formatted]
|
| 1024 |
-
basic_ostream<charT,traits>&
|
| 1025 |
-
basic_ostream<charT,traits>& (*pf)(basic_ostream<charT,traits>&));
|
| 1026 |
-
basic_ostream<charT,traits>&
|
| 1027 |
-
basic_ios<charT,traits>& (*pf)(basic_ios<charT,traits>&));
|
| 1028 |
-
basic_ostream<charT,traits>&
|
| 1029 |
-
ios_base& (*pf)(ios_base&));
|
| 1030 |
|
| 1031 |
basic_ostream<charT, traits>& operator<<(bool n);
|
| 1032 |
basic_ostream<charT, traits>& operator<<(short n);
|
| 1033 |
basic_ostream<charT, traits>& operator<<(unsigned short n);
|
| 1034 |
basic_ostream<charT, traits>& operator<<(int n);
|
|
@@ -1040,75 +1038,65 @@ namespace std {
|
|
| 1040 |
basic_ostream<charT, traits>& operator<<(float f);
|
| 1041 |
basic_ostream<charT, traits>& operator<<(double f);
|
| 1042 |
basic_ostream<charT, traits>& operator<<(long double f);
|
| 1043 |
|
| 1044 |
basic_ostream<charT, traits>& operator<<(const void* p);
|
| 1045 |
-
basic_ostream<charT,traits>& operator<<(
|
| 1046 |
-
|
| 1047 |
|
| 1048 |
-
// [ostream.unformatted]
|
| 1049 |
basic_ostream<charT, traits>& put(char_type c);
|
| 1050 |
basic_ostream<charT, traits>& write(const char_type* s, streamsize n);
|
| 1051 |
|
| 1052 |
basic_ostream<charT, traits>& flush();
|
| 1053 |
|
| 1054 |
-
// [ostream.seeks] seeks
|
| 1055 |
pos_type tellp();
|
| 1056 |
basic_ostream<charT, traits>& seekp(pos_type);
|
| 1057 |
basic_ostream<charT, traits>& seekp(off_type, ios_base::seekdir);
|
|
|
|
| 1058 |
protected:
|
|
|
|
| 1059 |
basic_ostream(const basic_ostream& rhs) = delete;
|
| 1060 |
basic_ostream(basic_ostream&& rhs);
|
| 1061 |
|
| 1062 |
-
// [ostream.assign]
|
| 1063 |
basic_ostream& operator=(const basic_ostream& rhs) = delete;
|
| 1064 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 1065 |
void swap(basic_ostream& rhs);
|
| 1066 |
};
|
| 1067 |
|
| 1068 |
-
// [ostream.inserters.character] character inserters
|
| 1069 |
template<class charT, class traits>
|
| 1070 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&,
|
| 1071 |
-
charT);
|
| 1072 |
template<class charT, class traits>
|
| 1073 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&,
|
| 1074 |
-
char);
|
| 1075 |
template<class traits>
|
| 1076 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 1077 |
-
char);
|
| 1078 |
|
| 1079 |
-
// signed and unsigned
|
| 1080 |
template<class traits>
|
| 1081 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 1082 |
-
signed char);
|
| 1083 |
template<class traits>
|
| 1084 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 1085 |
-
unsigned char);
|
| 1086 |
|
| 1087 |
template<class charT, class traits>
|
| 1088 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&,
|
| 1089 |
-
const charT*);
|
| 1090 |
template<class charT, class traits>
|
| 1091 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&,
|
| 1092 |
-
const char*);
|
| 1093 |
template<class traits>
|
| 1094 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 1095 |
-
const char*);
|
| 1096 |
|
| 1097 |
-
// signed and unsigned
|
| 1098 |
template<class traits>
|
| 1099 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 1100 |
-
const signed char*);
|
| 1101 |
template<class traits>
|
| 1102 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 1103 |
-
const unsigned char*);
|
| 1104 |
}
|
| 1105 |
```
|
| 1106 |
|
| 1107 |
-
The class `basic_ostream` defines a number of member function
|
| 1108 |
-
that assist in formatting and writing output to output
|
| 1109 |
-
controlled by a stream buffer.
|
| 1110 |
|
| 1111 |
Two groups of member function signatures share common properties: the
|
| 1112 |
*formatted output functions* (or *inserters*) and the *unformatted
|
| 1113 |
output functions.* Both groups of output functions generate (or
|
| 1114 |
*insert*) output *characters* by actions equivalent to calling
|
|
@@ -1120,45 +1108,55 @@ If one of these called functions throws an exception, then unless
|
|
| 1120 |
explicitly noted otherwise the output function sets `badbit` in error
|
| 1121 |
state. If `badbit` is on in `exceptions()`, the output function rethrows
|
| 1122 |
the exception without completing its actions, otherwise it does not
|
| 1123 |
throw anything and treat as an error.
|
| 1124 |
|
| 1125 |
-
#### `basic_ostream` constructors <a id="ostream.cons">[[ostream.cons]]</a>
|
| 1126 |
|
| 1127 |
``` cpp
|
| 1128 |
explicit basic_ostream(basic_streambuf<charT, traits>* sb);
|
| 1129 |
```
|
| 1130 |
|
| 1131 |
-
``
|
| 1132 |
-
|
| 1133 |
-
``
|
|
|
|
|
|
|
| 1134 |
|
| 1135 |
``` cpp
|
| 1136 |
basic_ostream(basic_ostream&& rhs);
|
| 1137 |
```
|
| 1138 |
|
| 1139 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 1140 |
by default constructing the base class and calling
|
| 1141 |
`basic_ios<charT, traits>::move(rhs)` to initialize the base class.
|
| 1142 |
|
| 1143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1144 |
|
| 1145 |
``` cpp
|
| 1146 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 1147 |
```
|
| 1148 |
|
| 1149 |
-
*Effects:* `swap(rhs)`.
|
| 1150 |
|
| 1151 |
*Returns:* `*this`.
|
| 1152 |
|
| 1153 |
``` cpp
|
| 1154 |
void swap(basic_ostream& rhs);
|
| 1155 |
```
|
| 1156 |
|
| 1157 |
*Effects:* Calls `basic_ios<charT, traits>::swap(rhs)`.
|
| 1158 |
|
| 1159 |
-
#### Class `basic_ostream::sentry` <a id="ostream::sentry">[[ostream::sentry]]</a>
|
| 1160 |
|
| 1161 |
``` cpp
|
| 1162 |
namespace std {
|
| 1163 |
template <class charT, class traits = char_traits<charT>>
|
| 1164 |
class basic_ostream<charT, traits>::sentry {
|
|
@@ -1180,45 +1178,55 @@ exception safe prefix and suffix operations.
|
|
| 1180 |
``` cpp
|
| 1181 |
explicit sentry(basic_ostream<charT, traits>& os);
|
| 1182 |
```
|
| 1183 |
|
| 1184 |
If `os.good()` is nonzero, prepares for formatted or unformatted output.
|
| 1185 |
-
If `os.tie()` is not a null pointer, calls `os.tie()->flush()`.[^
|
| 1186 |
|
| 1187 |
If, after any preparation is completed, `os.good()` is `true`,
|
| 1188 |
`ok_ == true` otherwise, `ok_ == false`. During preparation, the
|
| 1189 |
constructor may call `setstate(failbit)` (which may throw
|
| 1190 |
-
`ios_base::failure` ([[iostate.flags]]))[^
|
| 1191 |
|
| 1192 |
``` cpp
|
| 1193 |
~sentry();
|
| 1194 |
```
|
| 1195 |
|
| 1196 |
If
|
| 1197 |
-
`(
|
| 1198 |
is `true`, calls `os.rdbuf()->pubsync()`. If that function returns -1,
|
| 1199 |
sets `badbit` in `os.rdstate()` without propagating an exception.
|
| 1200 |
|
| 1201 |
``` cpp
|
| 1202 |
explicit operator bool() const;
|
| 1203 |
```
|
| 1204 |
|
| 1205 |
*Effects:* Returns `ok_`.
|
| 1206 |
|
| 1207 |
-
#### `basic_ostream` seek members <a id="ostream.seeks">[[ostream.seeks]]</a>
|
| 1208 |
|
| 1209 |
Each seek member function begins execution by constructing an object of
|
| 1210 |
class `sentry`. It returns by destroying the `sentry` object.
|
| 1211 |
|
| 1212 |
``` cpp
|
| 1213 |
pos_type tellp();
|
| 1214 |
```
|
| 1215 |
|
|
|
|
|
|
|
|
|
|
| 1216 |
``` cpp
|
| 1217 |
basic_ostream<charT, traits>& seekp(pos_type pos);
|
| 1218 |
```
|
| 1219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1220 |
``` cpp
|
| 1221 |
basic_ostream<charT, traits>& seekp(off_type off, ios_base::seekdir dir);
|
| 1222 |
```
|
| 1223 |
|
| 1224 |
*Effects:* If `fail() != true`, executes
|
|
@@ -1236,11 +1244,11 @@ Each formatted output function begins execution by constructing an
|
|
| 1236 |
object of class `sentry`. If this object returns `true` when converted
|
| 1237 |
to a value of type `bool`, the function endeavors to generate the
|
| 1238 |
requested output. If the generation fails, then the formatted output
|
| 1239 |
function does `setstate(ios_base::failbit)`, which might throw an
|
| 1240 |
exception. If an exception is thrown during output, then `ios::badbit`
|
| 1241 |
-
is turned on[^
|
| 1242 |
`(exceptions()&badbit) != 0` then the exception is rethrown. Whether or
|
| 1243 |
not an exception is thrown, the `sentry` object is destroyed before
|
| 1244 |
leaving the formatted output function. If no exception is thrown, the
|
| 1245 |
result of the formatted output function is `*this`.
|
| 1246 |
|
|
@@ -1337,59 +1345,57 @@ bool failed = use_facet<
|
|
| 1337 |
The first argument provides an object of the `ostreambuf_iterator<>`
|
| 1338 |
class which is an iterator for class `basic_ostream<>`. It bypasses
|
| 1339 |
`ostream`s and uses `streambuf`s directly. Class `locale` relies on
|
| 1340 |
these types as its interface to iostreams, since for flexibility it has
|
| 1341 |
been abstracted away from direct dependence on `ostream`. The second
|
| 1342 |
-
parameter is a reference to the base subobject of type `ios_base`.
|
| 1343 |
-
provides formatting specifications such as field width, and a locale
|
| 1344 |
from which to obtain other facets. If `failed` is `true` then does
|
| 1345 |
`setstate(badbit)`, which may throw an exception, and returns.
|
| 1346 |
|
| 1347 |
*Returns:* `*this`.
|
| 1348 |
|
| 1349 |
##### `basic_ostream::operator<<` <a id="ostream.inserters">[[ostream.inserters]]</a>
|
| 1350 |
|
| 1351 |
``` cpp
|
| 1352 |
-
basic_ostream<charT,traits>&
|
| 1353 |
-
|
| 1354 |
```
|
| 1355 |
|
| 1356 |
*Effects:* None. Does not behave as a formatted output function (as
|
| 1357 |
described in [[ostream.formatted.reqmts]]).
|
| 1358 |
|
| 1359 |
-
*Returns:* `pf(*this)`.[^
|
| 1360 |
|
| 1361 |
``` cpp
|
| 1362 |
-
basic_ostream<charT,traits>&
|
| 1363 |
-
|
| 1364 |
```
|
| 1365 |
|
| 1366 |
*Effects:* Calls `pf(*this)`. This inserter does not behave as a
|
| 1367 |
formatted output function (as described
|
| 1368 |
in [[ostream.formatted.reqmts]]).
|
| 1369 |
|
| 1370 |
-
*Returns:* `*this`.[^
|
| 1371 |
|
| 1372 |
``` cpp
|
| 1373 |
-
basic_ostream<charT,traits>& operator<<
|
| 1374 |
-
(ios_base& (*pf)(ios_base&));
|
| 1375 |
```
|
| 1376 |
|
| 1377 |
*Effects:* Calls `pf(*this)`. This inserter does not behave as a
|
| 1378 |
formatted output function (as described
|
| 1379 |
in [[ostream.formatted.reqmts]]).
|
| 1380 |
|
| 1381 |
*Returns:* `*this`.
|
| 1382 |
|
| 1383 |
``` cpp
|
| 1384 |
-
basic_ostream<charT,traits>& operator<<
|
| 1385 |
-
(basic_streambuf<charT,traits>* sb);
|
| 1386 |
```
|
| 1387 |
|
| 1388 |
-
*Effects:* Behaves as an unformatted output function
|
| 1389 |
-
|
| 1390 |
-
|
| 1391 |
`ios_base::failure`).
|
| 1392 |
|
| 1393 |
Gets characters from `sb` and inserts them in `*this`. Characters are
|
| 1394 |
read from `sb` and inserted until any of the following occurs:
|
| 1395 |
|
|
@@ -1404,55 +1410,58 @@ exception was thrown while extracting a character, the function sets
|
|
| 1404 |
`failbit` in error state, and if `failbit` is on in `exceptions()` the
|
| 1405 |
caught exception is rethrown.
|
| 1406 |
|
| 1407 |
*Returns:* `*this`.
|
| 1408 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1409 |
##### Character inserter function templates <a id="ostream.inserters.character">[[ostream.inserters.character]]</a>
|
| 1410 |
|
| 1411 |
``` cpp
|
| 1412 |
template<class charT, class traits>
|
| 1413 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
|
| 1414 |
-
charT c);
|
| 1415 |
template<class charT, class traits>
|
| 1416 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
|
| 1417 |
-
char c);
|
| 1418 |
// specialization
|
| 1419 |
template<class traits>
|
| 1420 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 1421 |
-
char c);
|
| 1422 |
// signed and unsigned
|
| 1423 |
template<class traits>
|
| 1424 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 1425 |
-
signed char c);
|
| 1426 |
template<class traits>
|
| 1427 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 1428 |
-
unsigned char c);
|
| 1429 |
```
|
| 1430 |
|
| 1431 |
-
*Effects:* Behaves as a formatted output
|
| 1432 |
-
(
|
| 1433 |
-
sequence `seq`. If `c` has type `char` and the character type
|
| 1434 |
-
stream is not `char`, then `seq` consists of `out.widen(c)`;
|
| 1435 |
-
`seq` consists of `c`. Determines padding for `seq` as
|
| 1436 |
-
in [[ostream.formatted.reqmts]]. Inserts `seq` into `out`.
|
| 1437 |
-
`os.width(0)`.
|
| 1438 |
|
| 1439 |
*Returns:* `out`.
|
| 1440 |
|
| 1441 |
``` cpp
|
| 1442 |
template<class charT, class traits>
|
| 1443 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
|
| 1444 |
-
const charT* s);
|
| 1445 |
template<class charT, class traits>
|
| 1446 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
|
| 1447 |
-
const char* s);
|
| 1448 |
template<class traits>
|
| 1449 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 1450 |
-
const char* s);
|
| 1451 |
template<class traits>
|
| 1452 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 1453 |
-
const signed char* s);
|
| 1454 |
template<class traits>
|
| 1455 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out,
|
| 1456 |
const unsigned char* s);
|
| 1457 |
```
|
| 1458 |
|
|
@@ -1467,11 +1476,11 @@ would be computed as if by:
|
|
| 1467 |
- `traits::length(s)` for the overload where the first argument is of
|
| 1468 |
type `basic_ostream<charT, traits>&` and the second is of type
|
| 1469 |
`const charT*`, and also for the overload where the first argument is
|
| 1470 |
of type `basic_ostream<char, traits>&` and the second is of type
|
| 1471 |
`const char*`,
|
| 1472 |
-
- `
|
| 1473 |
argument is of type `basic_ostream<charT, traits>&` and the second is
|
| 1474 |
of type `const char*`,
|
| 1475 |
- `traits::length(reinterpret_cast<const char*>(s))` for the other two
|
| 1476 |
overloads.
|
| 1477 |
|
|
@@ -1485,23 +1494,23 @@ in [[ostream.formatted.reqmts]]. Inserts `seq` into `out`. Calls
|
|
| 1485 |
|
| 1486 |
Each unformatted output function begins execution by constructing an
|
| 1487 |
object of class `sentry`. If this object returns `true`, while
|
| 1488 |
converting to a value of type `bool`, the function endeavors to generate
|
| 1489 |
the requested output. If an exception is thrown during output, then
|
| 1490 |
-
`ios::badbit` is turned on[^
|
| 1491 |
`(exceptions() & badbit) != 0` then the exception is rethrown. In any
|
| 1492 |
case, the unformatted output function ends by destroying the sentry
|
| 1493 |
object, then, if no exception was thrown, returning the value specified
|
| 1494 |
for the unformatted output function.
|
| 1495 |
|
| 1496 |
``` cpp
|
| 1497 |
basic_ostream<charT, traits>& put(char_type c);
|
| 1498 |
```
|
| 1499 |
|
| 1500 |
*Effects:* Behaves as an unformatted output function (as described
|
| 1501 |
-
|
| 1502 |
-
|
| 1503 |
|
| 1504 |
Otherwise, calls `setstate(badbit)` (which may throw
|
| 1505 |
`ios_base::failure` ([[iostate.flags]])).
|
| 1506 |
|
| 1507 |
*Returns:* `*this`.
|
|
@@ -1509,14 +1518,14 @@ Otherwise, calls `setstate(badbit)` (which may throw
|
|
| 1509 |
``` cpp
|
| 1510 |
basic_ostream& write(const char_type* s, streamsize n);
|
| 1511 |
```
|
| 1512 |
|
| 1513 |
*Effects:* Behaves as an unformatted output function (as described
|
| 1514 |
-
|
| 1515 |
-
|
| 1516 |
-
|
| 1517 |
-
|
| 1518 |
|
| 1519 |
- `n` characters are inserted;
|
| 1520 |
- inserting in the output sequence fails (in which case the function
|
| 1521 |
calls `setstate(badbit)`, which may throw
|
| 1522 |
`ios_base::failure` ([[iostate.flags]])).
|
|
@@ -1526,67 +1535,62 @@ inserted until either of the following occurs:
|
|
| 1526 |
``` cpp
|
| 1527 |
basic_ostream& flush();
|
| 1528 |
```
|
| 1529 |
|
| 1530 |
*Effects:* Behaves as an unformatted output function (as described
|
| 1531 |
-
|
| 1532 |
-
|
| 1533 |
-
|
| 1534 |
-
`
|
| 1535 |
-
`setstate(badbit)` (which may throw
|
| 1536 |
`ios_base::failure` ([[iostate.flags]])). Otherwise, if the sentry
|
| 1537 |
object returns `false`, does nothing.
|
| 1538 |
|
| 1539 |
*Returns:* `*this`.
|
| 1540 |
|
| 1541 |
#### Standard `basic_ostream` manipulators <a id="ostream.manip">[[ostream.manip]]</a>
|
| 1542 |
|
| 1543 |
``` cpp
|
| 1544 |
-
namespace std {
|
| 1545 |
template <class charT, class traits>
|
| 1546 |
basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);
|
| 1547 |
-
}
|
| 1548 |
```
|
| 1549 |
|
| 1550 |
*Effects:* Calls `os.put(os.widen(’\n’))`, then `os.flush()`.
|
| 1551 |
|
| 1552 |
*Returns:* `os`.
|
| 1553 |
|
| 1554 |
``` cpp
|
| 1555 |
-
namespace std {
|
| 1556 |
template <class charT, class traits>
|
| 1557 |
basic_ostream<charT, traits>& ends(basic_ostream<charT, traits>& os);
|
| 1558 |
-
}
|
| 1559 |
```
|
| 1560 |
|
| 1561 |
*Effects:* Inserts a null character into the output sequence: calls
|
| 1562 |
`os.put(charT())`.
|
| 1563 |
|
| 1564 |
*Returns:* `os`.
|
| 1565 |
|
| 1566 |
``` cpp
|
| 1567 |
-
namespace std {
|
| 1568 |
template <class charT, class traits>
|
| 1569 |
basic_ostream<charT, traits>& flush(basic_ostream<charT, traits>& os);
|
| 1570 |
-
}
|
| 1571 |
```
|
| 1572 |
|
| 1573 |
*Effects:* Calls `os.flush()`.
|
| 1574 |
|
| 1575 |
*Returns:* `os`.
|
| 1576 |
|
| 1577 |
#### Rvalue stream insertion <a id="ostream.rvalue">[[ostream.rvalue]]</a>
|
| 1578 |
|
| 1579 |
``` cpp
|
| 1580 |
template <class charT, class traits, class T>
|
| 1581 |
-
basic_ostream<charT, traits>&
|
| 1582 |
-
operator<<(basic_ostream<charT, traits>&& os, const T& x);
|
| 1583 |
```
|
| 1584 |
|
| 1585 |
-
*Effects:* `os << x`
|
| 1586 |
|
| 1587 |
-
*Returns:* `os`
|
|
|
|
|
|
|
|
|
|
| 1588 |
|
| 1589 |
### Standard manipulators <a id="std.manip">[[std.manip]]</a>
|
| 1590 |
|
| 1591 |
The header `<iomanip>` defines several functions that support extractors
|
| 1592 |
and inserters that alter information maintained by class `ios_base` and
|
|
@@ -1596,59 +1600,59 @@ its derived classes.
|
|
| 1596 |
unspecified resetiosflags(ios_base::fmtflags mask);
|
| 1597 |
```
|
| 1598 |
|
| 1599 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1600 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1601 |
-
`out <<
|
| 1602 |
if `in` is an object of type `basic_istream<charT, traits>` then the
|
| 1603 |
-
expression `in >>
|
| 1604 |
-
`f(in, mask)`, where the function `f` is defined as:[^
|
| 1605 |
|
| 1606 |
``` cpp
|
| 1607 |
void f(ios_base& str, ios_base::fmtflags mask) {
|
| 1608 |
// reset specified flags
|
| 1609 |
str.setf(ios_base::fmtflags(0), mask);
|
| 1610 |
}
|
| 1611 |
```
|
| 1612 |
|
| 1613 |
-
The expression `out <<
|
| 1614 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1615 |
-
`in >>
|
| 1616 |
`basic_istream<charT, traits>&` and value `in`.
|
| 1617 |
|
| 1618 |
``` cpp
|
| 1619 |
unspecified setiosflags(ios_base::fmtflags mask);
|
| 1620 |
```
|
| 1621 |
|
| 1622 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1623 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1624 |
-
`out <<
|
| 1625 |
`in` is an object of type `basic_istream<charT, traits>` then the
|
| 1626 |
-
expression `in >>
|
| 1627 |
`f(in, mask)`, where the function `f` is defined as:
|
| 1628 |
|
| 1629 |
``` cpp
|
| 1630 |
void f(ios_base& str, ios_base::fmtflags mask) {
|
| 1631 |
// set specified flags
|
| 1632 |
str.setf(mask);
|
| 1633 |
}
|
| 1634 |
```
|
| 1635 |
|
| 1636 |
-
The expression `out <<
|
| 1637 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1638 |
-
`in >>
|
| 1639 |
`traits>&` and value `in`.
|
| 1640 |
|
| 1641 |
``` cpp
|
| 1642 |
unspecified setbase(int base);
|
| 1643 |
```
|
| 1644 |
|
| 1645 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1646 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1647 |
-
`out <<
|
| 1648 |
`in` is an object of type `basic_istream<charT, traits>` then the
|
| 1649 |
-
expression `in >>
|
| 1650 |
where the function `f` is defined as:
|
| 1651 |
|
| 1652 |
``` cpp
|
| 1653 |
void f(ios_base& str, int base) {
|
| 1654 |
// set basefield
|
|
@@ -1657,79 +1661,79 @@ void f(ios_base& str, int base) {
|
|
| 1657 |
base == 16 ? ios_base::hex :
|
| 1658 |
ios_base::fmtflags(0), ios_base::basefield);
|
| 1659 |
}
|
| 1660 |
```
|
| 1661 |
|
| 1662 |
-
The expression `out <<
|
| 1663 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1664 |
-
`in >>
|
| 1665 |
and value `in`.
|
| 1666 |
|
| 1667 |
``` cpp
|
| 1668 |
unspecified setfill(char_type c);
|
| 1669 |
```
|
| 1670 |
|
| 1671 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1672 |
of type `basic_ostream<charT, traits>` and `c` has type `charT` then the
|
| 1673 |
-
expression `out <<
|
| 1674 |
where the function `f` is defined as:
|
| 1675 |
|
| 1676 |
``` cpp
|
| 1677 |
template<class charT, class traits>
|
| 1678 |
void f(basic_ios<charT, traits>& str, charT c) {
|
| 1679 |
// set fill character
|
| 1680 |
str.fill(c);
|
| 1681 |
}
|
| 1682 |
```
|
| 1683 |
|
| 1684 |
-
The expression `out <<
|
| 1685 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1686 |
|
| 1687 |
``` cpp
|
| 1688 |
unspecified setprecision(int n);
|
| 1689 |
```
|
| 1690 |
|
| 1691 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1692 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1693 |
-
`out <<
|
| 1694 |
is an object of type `basic_istream<charT, traits>` then the expression
|
| 1695 |
-
`in >>
|
| 1696 |
function `f` is defined as:
|
| 1697 |
|
| 1698 |
``` cpp
|
| 1699 |
void f(ios_base& str, int n) {
|
| 1700 |
// set precision
|
| 1701 |
str.precision(n);
|
| 1702 |
}
|
| 1703 |
```
|
| 1704 |
|
| 1705 |
-
The expression `out <<
|
| 1706 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1707 |
-
`in >>
|
| 1708 |
and value `in`.
|
| 1709 |
|
| 1710 |
``` cpp
|
| 1711 |
unspecified setw(int n);
|
| 1712 |
```
|
| 1713 |
|
| 1714 |
*Returns:* An object of unspecified type such that if `out` is an
|
| 1715 |
instance of `basic_ostream<charT, traits>` then the expression
|
| 1716 |
-
`out <<
|
| 1717 |
object of type `basic_istream<charT, traits>` then the expression
|
| 1718 |
-
`in >>
|
| 1719 |
`f` is defined as:
|
| 1720 |
|
| 1721 |
``` cpp
|
| 1722 |
void f(ios_base& str, int n) {
|
| 1723 |
// set width
|
| 1724 |
str.width(n);
|
| 1725 |
}
|
| 1726 |
```
|
| 1727 |
|
| 1728 |
-
The expression `out <<
|
| 1729 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1730 |
-
`in >>
|
| 1731 |
value `in`.
|
| 1732 |
|
| 1733 |
### Extended manipulators <a id="ext.manip">[[ext.manip]]</a>
|
| 1734 |
|
| 1735 |
The header `<iomanip>` defines several functions that support extractors
|
|
@@ -1746,18 +1750,18 @@ specialization of the `basic_string` template (Clause [[strings]]).
|
|
| 1746 |
*Effects:* The expression `in >> get_money(mon, intl)` described below
|
| 1747 |
behaves as a formatted input function ([[istream.formatted.reqmts]]).
|
| 1748 |
|
| 1749 |
*Returns:* An object of unspecified type such that if `in` is an object
|
| 1750 |
of type `basic_istream<charT, traits>` then the expression
|
| 1751 |
-
`in >>
|
| 1752 |
where the function `f` is defined as:
|
| 1753 |
|
| 1754 |
``` cpp
|
| 1755 |
template <class charT, class traits, class moneyT>
|
| 1756 |
void f(basic_ios<charT, traits>& str, moneyT& mon, bool intl) {
|
| 1757 |
-
|
| 1758 |
-
|
| 1759 |
|
| 1760 |
ios_base::iostate err = ios_base::goodbit;
|
| 1761 |
const MoneyGet& mg = use_facet<MoneyGet>(str.getloc());
|
| 1762 |
|
| 1763 |
mg.get(Iter(str.rdbuf()), Iter(), intl, str, err, mon);
|
|
@@ -1765,11 +1769,11 @@ void f(basic_ios<charT, traits>& str, moneyT& mon, bool intl) {
|
|
| 1765 |
if (ios_base::goodbit != err)
|
| 1766 |
str.setstate(err);
|
| 1767 |
}
|
| 1768 |
```
|
| 1769 |
|
| 1770 |
-
The expression `in >>
|
| 1771 |
`basic_istream<charT, traits>&` and value `in`.
|
| 1772 |
|
| 1773 |
``` cpp
|
| 1774 |
template <class moneyT> unspecified put_money(const moneyT& mon, bool intl = false);
|
| 1775 |
```
|
|
@@ -1777,62 +1781,63 @@ template <class moneyT> unspecified put_money(const moneyT& mon, bool intl = fal
|
|
| 1777 |
*Requires:* The type `moneyT` shall be either `long double` or a
|
| 1778 |
specialization of the `basic_string` template (Clause [[strings]]).
|
| 1779 |
|
| 1780 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1781 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1782 |
-
`out <<
|
| 1783 |
-
calls `f(out, mon, intl)`,
|
|
|
|
| 1784 |
|
| 1785 |
``` cpp
|
| 1786 |
template <class charT, class traits, class moneyT>
|
| 1787 |
void f(basic_ios<charT, traits>& str, const moneyT& mon, bool intl) {
|
| 1788 |
-
|
| 1789 |
-
|
| 1790 |
|
| 1791 |
const MoneyPut& mp = use_facet<MoneyPut>(str.getloc());
|
| 1792 |
const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon);
|
| 1793 |
|
| 1794 |
if (end.failed())
|
| 1795 |
str.setstate(ios::badbit);
|
| 1796 |
}
|
| 1797 |
```
|
| 1798 |
|
| 1799 |
-
The expression `out <<
|
| 1800 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1801 |
|
| 1802 |
``` cpp
|
| 1803 |
template <class charT> unspecified get_time(struct tm* tmb, const charT* fmt);
|
| 1804 |
```
|
| 1805 |
|
| 1806 |
*Requires:* The argument `tmb` shall be a valid pointer to an object of
|
| 1807 |
-
type `struct tm`
|
| 1808 |
array of objects of type `charT` with `char_traits<charT>::length(fmt)`
|
| 1809 |
elements.
|
| 1810 |
|
| 1811 |
*Returns:* An object of unspecified type such that if `in` is an object
|
| 1812 |
of type `basic_istream<charT, traits>` then the expression
|
| 1813 |
-
`in >>
|
| 1814 |
where the function `f` is defined as:
|
| 1815 |
|
| 1816 |
``` cpp
|
| 1817 |
template <class charT, class traits>
|
| 1818 |
void f(basic_ios<charT, traits>& str, struct tm* tmb, const charT* fmt) {
|
| 1819 |
-
|
| 1820 |
-
|
| 1821 |
|
| 1822 |
ios_base::iostate err = ios_base::goodbit;
|
| 1823 |
const TimeGet& tg = use_facet<TimeGet>(str.getloc());
|
| 1824 |
|
| 1825 |
tg.get(Iter(str.rdbuf()), Iter(), str, err, tmb,
|
| 1826 |
fmt, fmt + traits::length(fmt));
|
| 1827 |
|
| 1828 |
if (err != ios_base::goodbit)
|
| 1829 |
-
str.setstate(err)
|
| 1830 |
}
|
| 1831 |
```
|
| 1832 |
|
| 1833 |
-
The expression `in >>
|
| 1834 |
`basic_istream<charT, traits>&` and value `in`.
|
| 1835 |
|
| 1836 |
``` cpp
|
| 1837 |
template <class charT> unspecified put_time(const struct tm* tmb, const charT* fmt);
|
| 1838 |
```
|
|
@@ -1842,51 +1847,55 @@ type `struct tm`, and the argument `fmt` shall be a valid pointer to an
|
|
| 1842 |
array of objects of type `charT` with `char_traits<charT>::length(fmt)`
|
| 1843 |
elements.
|
| 1844 |
|
| 1845 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1846 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1847 |
-
`out <<
|
| 1848 |
where the function `f` is defined as:
|
| 1849 |
|
| 1850 |
``` cpp
|
| 1851 |
template <class charT, class traits>
|
| 1852 |
void f(basic_ios<charT, traits>& str, const struct tm* tmb, const charT* fmt) {
|
| 1853 |
-
|
| 1854 |
-
|
| 1855 |
|
| 1856 |
const TimePut& tp = use_facet<TimePut>(str.getloc());
|
| 1857 |
const Iter end = tp.put(Iter(str.rdbuf()), str, str.fill(), tmb,
|
| 1858 |
fmt, fmt + traits::length(fmt));
|
| 1859 |
|
| 1860 |
if (end.failed())
|
| 1861 |
str.setstate(ios_base::badbit);
|
| 1862 |
}
|
| 1863 |
```
|
| 1864 |
|
| 1865 |
-
The expression `out <<
|
| 1866 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1867 |
|
| 1868 |
### Quoted manipulators <a id="quoted.manip">[[quoted.manip]]</a>
|
| 1869 |
|
| 1870 |
-
Quoted manipulators provide string insertion and extraction
|
| 1871 |
-
strings (for example, XML and CSV formats). Quoted
|
| 1872 |
-
useful in ensuring that the content of a string with
|
| 1873 |
-
remains unchanged if inserted and then extracted via
|
|
|
|
| 1874 |
|
| 1875 |
``` cpp
|
| 1876 |
template <class charT>
|
| 1877 |
unspecified quoted(const charT* s, charT delim = charT('"'), charT escape = charT('\\'));
|
| 1878 |
template <class charT, class traits, class Allocator>
|
| 1879 |
unspecified quoted(const basic_string<charT, traits, Allocator>& s,
|
| 1880 |
-
|
|
|
|
|
|
|
|
|
|
| 1881 |
```
|
| 1882 |
|
| 1883 |
*Returns:* An object of unspecified type such that if `out` is an
|
| 1884 |
instance of `basic_ostream` with member type `char_type` the same as
|
| 1885 |
-
`charT` and with member type `traits_type`, which in the second
|
| 1886 |
-
the same as `traits`, then the expression
|
| 1887 |
-
`out <<
|
| 1888 |
function ([[ostream.formatted.reqmts]]) of `out`. This forms a
|
| 1889 |
character sequence `seq`, initially consisting of the following
|
| 1890 |
elements:
|
| 1891 |
|
| 1892 |
- `delim`.
|
|
@@ -1897,45 +1906,45 @@ elements:
|
|
| 1897 |
|
| 1898 |
Let `x` be the number of elements initially in `seq`. Then padding is
|
| 1899 |
determined for `seq` as described in [[ostream.formatted.reqmts]],
|
| 1900 |
`seq` is inserted as if by calling `out.rdbuf()->sputn(seq, n)`, where
|
| 1901 |
`n` is the larger of `out.width()` and `x`, and `out.width(0)` is
|
| 1902 |
-
called. The expression `out <<
|
| 1903 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1904 |
|
| 1905 |
``` cpp
|
| 1906 |
template <class charT, class traits, class Allocator>
|
| 1907 |
unspecified quoted(basic_string<charT, traits, Allocator>& s,
|
| 1908 |
-
|
| 1909 |
```
|
| 1910 |
|
| 1911 |
*Returns:* An object of unspecified type such that:
|
| 1912 |
|
| 1913 |
- If `in` is an instance of `basic_istream` with member types
|
| 1914 |
`char_type` and `traits_type` the same as `charT` and `traits`,
|
| 1915 |
-
respectively, then the expression `in >>
|
| 1916 |
behaves as if it extracts the following characters from `in` using
|
| 1917 |
-
`
|
| 1918 |
-
`ios_base::failure` ([[ios::failure]]):
|
| 1919 |
- If the first character extracted is equal to `delim`, as determined
|
| 1920 |
by `traits_type::eq`, then:
|
| 1921 |
- Turn off the `skipws` flag.
|
| 1922 |
- `s.clear()`
|
| 1923 |
- Until an unescaped `delim` character is reached or `!in`, extract
|
| 1924 |
characters from `in` and append them to `s`, except that if an
|
| 1925 |
`escape` is reached, ignore it and append the next character to
|
| 1926 |
`s`.
|
| 1927 |
- Discard the final `delim` character.
|
| 1928 |
- Restore the `skipws` flag to its original value.
|
| 1929 |
-
- Otherwise, `in >>
|
| 1930 |
- If `out` is an instance of `basic_ostream` with member types
|
| 1931 |
`char_type` and `traits_type` the same as `charT` and `traits`,
|
| 1932 |
-
respectively, then the expression `out <<
|
| 1933 |
behaves as specified for the
|
| 1934 |
`const basic_string<charT, traits, Allocator>&` overload of the
|
| 1935 |
`quoted` function.
|
| 1936 |
|
| 1937 |
-
The expression `in >>
|
| 1938 |
`basic_istream<charT, traits>&` and value `in`. The expression
|
| 1939 |
-
`out <<
|
| 1940 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1941 |
|
|
|
|
| 1 |
## Formatting and manipulators <a id="iostream.format">[[iostream.format]]</a>
|
| 2 |
|
| 3 |
+
### Header `<istream>` synopsis <a id="istream.syn">[[istream.syn]]</a>
|
|
|
|
|
|
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
namespace std {
|
| 7 |
template <class charT, class traits = char_traits<charT>>
|
| 8 |
class basic_istream;
|
| 9 |
+
|
| 10 |
+
using istream = basic_istream<char>;
|
| 11 |
+
using wistream = basic_istream<wchar_t>;
|
| 12 |
|
| 13 |
template <class charT, class traits = char_traits<charT>>
|
| 14 |
class basic_iostream;
|
| 15 |
+
|
| 16 |
+
using iostream = basic_iostream<char>;
|
| 17 |
+
using wiostream = basic_iostream<wchar_t>;
|
| 18 |
|
| 19 |
template <class charT, class traits>
|
| 20 |
basic_istream<charT, traits>& ws(basic_istream<charT, traits>& is);
|
| 21 |
|
| 22 |
template <class charT, class traits, class T>
|
| 23 |
+
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&& is, T&& x);
|
|
|
|
| 24 |
}
|
| 25 |
```
|
| 26 |
|
| 27 |
+
### Header `<ostream>` synopsis <a id="ostream.syn">[[ostream.syn]]</a>
|
| 28 |
+
|
| 29 |
``` cpp
|
| 30 |
namespace std {
|
| 31 |
template <class charT, class traits = char_traits<charT>>
|
| 32 |
class basic_ostream;
|
| 33 |
+
|
| 34 |
+
using ostream = basic_ostream<char>;
|
| 35 |
+
using wostream = basic_ostream<wchar_t>;
|
| 36 |
|
| 37 |
template <class charT, class traits>
|
| 38 |
basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);
|
| 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 |
|
| 49 |
+
### Header `<iomanip>` synopsis <a id="iomanip.syn">[[iomanip.syn]]</a>
|
| 50 |
+
|
| 51 |
``` cpp
|
| 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);
|
|
|
|
| 65 |
template <class charT>
|
| 66 |
T11 quoted(const charT* s, charT delim = charT('"'), charT escape = charT('\\'));
|
| 67 |
|
| 68 |
template <class charT, class traits, class Allocator>
|
| 69 |
T12 quoted(const basic_string<charT, traits, Allocator>& s,
|
| 70 |
+
\itcorr charT delim = charT('"'), charT escape = charT('\\'));
|
| 71 |
|
| 72 |
template <class charT, class traits, class Allocator>
|
| 73 |
T13 quoted(basic_string<charT, traits, Allocator>& s,
|
| 74 |
+
\itcorr charT delim = charT('"'), charT escape = charT('\\'));
|
| 75 |
+
|
| 76 |
+
template <class charT, class traits>
|
| 77 |
+
T14 quoted(basic_string_view<charT, traits> s,
|
| 78 |
+
\itcorr charT delim = charT('"'), charT escape = charT('\\'));
|
| 79 |
}
|
| 80 |
```
|
| 81 |
|
| 82 |
### Input streams <a id="input.streams">[[input.streams]]</a>
|
| 83 |
|
|
|
|
| 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 ([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::sentry], prefix/suffix
|
| 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>&));
|
| 112 |
+
basic_istream<charT, traits>&
|
| 113 |
+
operator>>(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));
|
| 114 |
+
basic_istream<charT, traits>&
|
| 115 |
+
operator>>(ios_base& (*pf)(ios_base&));
|
| 116 |
|
| 117 |
basic_istream<charT, traits>& operator>>(bool& n);
|
| 118 |
basic_istream<charT, traits>& operator>>(short& n);
|
| 119 |
basic_istream<charT, traits>& operator>>(unsigned short& n);
|
| 120 |
basic_istream<charT, traits>& operator>>(int& n);
|
|
|
|
| 126 |
basic_istream<charT, traits>& operator>>(float& f);
|
| 127 |
basic_istream<charT, traits>& operator>>(double& f);
|
| 128 |
basic_istream<charT, traits>& operator>>(long double& f);
|
| 129 |
|
| 130 |
basic_istream<charT, traits>& operator>>(void*& p);
|
| 131 |
+
basic_istream<charT, traits>& operator>>(basic_streambuf<char_type, traits>* sb);
|
|
|
|
| 132 |
|
| 133 |
+
// [istream.unformatted], unformatted input
|
| 134 |
streamsize gcount() const;
|
| 135 |
int_type get();
|
| 136 |
basic_istream<charT, traits>& get(char_type& c);
|
| 137 |
basic_istream<charT, traits>& get(char_type* s, streamsize n);
|
| 138 |
+
basic_istream<charT, traits>& get(char_type* s, streamsize n, char_type delim);
|
|
|
|
| 139 |
basic_istream<charT, traits>& get(basic_streambuf<char_type, traits>& sb);
|
| 140 |
+
basic_istream<charT, traits>& get(basic_streambuf<char_type, traits>& sb, char_type delim);
|
|
|
|
| 141 |
|
| 142 |
basic_istream<charT, traits>& getline(char_type* s, streamsize n);
|
| 143 |
+
basic_istream<charT, traits>& getline(char_type* s, streamsize n, char_type delim);
|
|
|
|
| 144 |
|
| 145 |
+
basic_istream<charT, traits>& ignore(streamsize n = 1, int_type delim = traits::eof());
|
|
|
|
| 146 |
int_type peek();
|
| 147 |
basic_istream<charT, traits>& read (char_type* s, streamsize n);
|
| 148 |
streamsize readsome(char_type* s, streamsize n);
|
| 149 |
|
| 150 |
basic_istream<charT, traits>& putback(char_type c);
|
|
|
|
| 154 |
pos_type tellg();
|
| 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& rhs) = delete;
|
| 161 |
basic_istream(basic_istream&& rhs);
|
| 162 |
|
| 163 |
+
// [istream.assign], assign and swap
|
| 164 |
basic_istream& operator=(const basic_istream& rhs) = delete;
|
| 165 |
basic_istream& operator=(basic_istream&& rhs);
|
| 166 |
void swap(basic_istream& rhs);
|
| 167 |
};
|
| 168 |
|
| 169 |
+
// [istream.extractors], character extraction templates
|
| 170 |
template<class charT, class traits>
|
| 171 |
+
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, charT&);
|
|
|
|
| 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
|
| 188 |
+
controlled by a stream buffer.
|
| 189 |
|
| 190 |
Two groups of member function signatures share common properties: the
|
| 191 |
*formatted input functions* (or *extractors*) and the *unformatted input
|
| 192 |
functions.* Both groups of input functions are described as if they
|
| 193 |
obtain (or *extract*) input *characters* by calling `rdbuf()->sbumpc()`
|
|
|
|
| 209 |
|
| 210 |
``` cpp
|
| 211 |
explicit basic_istream(basic_streambuf<charT, traits>* sb);
|
| 212 |
```
|
| 213 |
|
| 214 |
+
*Effects:* Constructs an object of class `basic_istream`, initializing
|
| 215 |
+
the base class subobject with
|
| 216 |
`basic_ios::init(sb)` ([[basic.ios.cons]]).
|
| 217 |
|
| 218 |
+
*Postconditions:* `gcount() == 0`.
|
| 219 |
|
| 220 |
``` cpp
|
| 221 |
basic_istream(basic_istream&& rhs);
|
| 222 |
```
|
| 223 |
|
|
|
|
| 238 |
|
| 239 |
``` cpp
|
| 240 |
basic_istream& operator=(basic_istream&& rhs);
|
| 241 |
```
|
| 242 |
|
| 243 |
+
*Effects:* As if by `swap(rhs)`.
|
| 244 |
|
| 245 |
*Returns:* `*this`.
|
| 246 |
|
| 247 |
``` cpp
|
| 248 |
void swap(basic_istream& rhs);
|
|
|
|
| 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_; }
|
|
|
|
| 282 |
to synchronize the output sequence with any associated external C
|
| 283 |
stream. Except that this call can be suppressed if the put area of
|
| 284 |
`is.tie()` is empty. Further an implementation is allowed to defer the
|
| 285 |
call to `flush` until a call of `is.rdbuf()->underflow()` occurs. If no
|
| 286 |
such call occurs before the `sentry` object is destroyed, the call to
|
| 287 |
+
`flush` may be eliminated entirely.[^18] If `noskipws` is zero and
|
| 288 |
`is.flags() & ios_base::skipws` is nonzero, the function extracts and
|
| 289 |
discards each character as long as the next available input character
|
| 290 |
`c` is a whitespace character. If `is.rdbuf()->sbumpc()` or
|
| 291 |
`is.rdbuf()->sgetc()` returns `traits::eof()`, the function calls
|
| 292 |
`setstate(failbit | eofbit)` (which may throw `ios_base::failure`).
|
| 293 |
|
| 294 |
*Remarks:* The constructor
|
| 295 |
+
|
| 296 |
+
``` cpp
|
| 297 |
+
explicit sentry(basic_istream<charT, traits>& is, bool noskipws = false)
|
| 298 |
+
```
|
| 299 |
+
|
| 300 |
uses the currently imbued locale in `is`, to determine whether the next
|
| 301 |
input character is whitespace or not.
|
| 302 |
|
| 303 |
To decide if the character `c` is a whitespace character, the
|
| 304 |
constructor performs as if it executes the following code fragment:
|
|
|
|
| 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` ([[iostate.flags]]))[^19]
|
| 316 |
|
| 317 |
``` cpp
|
| 318 |
~sentry();
|
| 319 |
```
|
| 320 |
|
|
|
|
| 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 `ios::badbit` is turned on[^20] in
|
| 338 |
`*this`’s error state. If `(exceptions()&badbit) != 0` then the
|
| 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 |
|
|
|
|
| 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 |
|
| 366 |
``` cpp
|
| 367 |
+
using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
|
| 368 |
iostate err = iostate::goodbit;
|
| 369 |
use_facet<numget>(loc).get(*this, 0, *this, err, val);
|
| 370 |
setstate(err);
|
| 371 |
```
|
| 372 |
|
| 373 |
In the above fragment, `loc` stands for the private member of the
|
| 374 |
+
`basic_ios` class.
|
| 375 |
+
|
| 376 |
+
[*Note 1*: The first argument provides an object of the
|
| 377 |
`istreambuf_iterator` class which is an iterator pointed to an input
|
| 378 |
+
stream. It bypasses istreams and uses streambufs
|
| 379 |
+
directly. — *end note*]
|
| 380 |
+
|
| 381 |
+
Class `locale` relies on this type as its interface to `istream`, so
|
| 382 |
+
that it does not need to depend directly on `istream`.
|
| 383 |
|
| 384 |
``` cpp
|
| 385 |
operator>>(short& val);
|
| 386 |
```
|
| 387 |
|
| 388 |
The conversion occurs as if performed by the following code fragment
|
| 389 |
(using the same notation as for the preceding code fragment):
|
| 390 |
|
| 391 |
``` cpp
|
| 392 |
+
using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
|
| 393 |
iostate err = ios_base::goodbit;
|
| 394 |
long lval;
|
| 395 |
use_facet<numget>(loc).get(*this, 0, *this, err, lval);
|
| 396 |
if (lval < numeric_limits<short>::min()) {
|
| 397 |
err |= ios_base::failbit;
|
|
|
|
| 410 |
|
| 411 |
The conversion occurs as if performed by the following code fragment
|
| 412 |
(using the same notation as for the preceding code fragment):
|
| 413 |
|
| 414 |
``` cpp
|
| 415 |
+
using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
|
| 416 |
iostate err = ios_base::goodbit;
|
| 417 |
long lval;
|
| 418 |
use_facet<numget>(loc).get(*this, 0, *this, err, lval);
|
| 419 |
if (lval < numeric_limits<int>::min()) {
|
| 420 |
err |= ios_base::failbit;
|
|
|
|
| 425 |
} else
|
| 426 |
val = static_cast<int>(lval);
|
| 427 |
setstate(err);
|
| 428 |
```
|
| 429 |
|
| 430 |
+
##### `basic_istream::operator>>` <a id="istream.extractors">[[istream.extractors]]</a>
|
| 431 |
|
| 432 |
``` cpp
|
| 433 |
+
basic_istream<charT, traits>&
|
| 434 |
+
operator>>(basic_istream<charT, traits>& (*pf)(basic_istream<charT, traits>&));
|
| 435 |
```
|
| 436 |
|
| 437 |
*Effects:* None. This extractor does not behave as a formatted input
|
| 438 |
+
function (as described in [[istream.formatted.reqmts]]).
|
| 439 |
|
| 440 |
+
*Returns:* `pf(*this)`.[^21]
|
| 441 |
|
| 442 |
``` cpp
|
| 443 |
+
basic_istream<charT, traits>&
|
| 444 |
+
operator>>(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));
|
| 445 |
```
|
| 446 |
|
| 447 |
*Effects:* Calls `pf(*this)`. This extractor does not behave as a
|
| 448 |
formatted input function (as described
|
| 449 |
in [[istream.formatted.reqmts]]).
|
| 450 |
|
| 451 |
*Returns:* `*this`.
|
| 452 |
|
| 453 |
``` cpp
|
| 454 |
+
basic_istream<charT, traits>& operator>>(ios_base& (*pf)(ios_base&));
|
|
|
|
| 455 |
```
|
| 456 |
|
| 457 |
+
*Effects:* Calls `pf(*this)`.[^22] This extractor does not behave as a
|
| 458 |
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* s);
|
|
|
|
| 466 |
template<class traits>
|
| 467 |
+
basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, unsigned char* s);
|
|
|
|
| 468 |
template<class traits>
|
| 469 |
+
basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, signed char* s);
|
|
|
|
| 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
|
|
|
|
| 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;
|
| 485 |
+
- letting `ct` be `use_facet<ctype<charT>>(in.getloc())`,
|
| 486 |
+
`ct.is(ct.space, c)` is `true`.
|
| 487 |
|
| 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 |
|
|
|
|
| 494 |
|
| 495 |
*Returns:* `in`.
|
| 496 |
|
| 497 |
``` cpp
|
| 498 |
template<class charT, class traits>
|
| 499 |
+
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& in, charT& c);
|
|
|
|
| 500 |
template<class traits>
|
| 501 |
+
basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, unsigned char& c);
|
|
|
|
| 502 |
template<class traits>
|
| 503 |
+
basic_istream<char, traits>& operator>>(basic_istream<char, traits>& in, signed char& c);
|
|
|
|
| 504 |
```
|
| 505 |
|
| 506 |
*Effects:* Behaves like a formatted input member (as described
|
| 507 |
in [[istream.formatted.reqmts]]) of `in`. After a `sentry` object is
|
| 508 |
constructed a character is extracted from `in`, if one is available, and
|
| 509 |
stored in `c`. Otherwise, the function calls `in.setstate(failbit)`.
|
| 510 |
|
| 511 |
*Returns:* `in`.
|
| 512 |
|
| 513 |
``` cpp
|
| 514 |
+
basic_istream<charT, traits>& operator>>(basic_streambuf<charT, traits>* sb);
|
|
|
|
| 515 |
```
|
| 516 |
|
| 517 |
+
*Effects:* Behaves as an unformatted input function
|
| 518 |
+
([[istream.unformatted]]). If `sb` is null, calls `setstate(failbit)`,
|
| 519 |
+
which may throw `ios_base::failure` ([[iostate.flags]]). After a sentry
|
| 520 |
+
object is constructed, extracts characters from `*this` and inserts them
|
| 521 |
+
in the output sequence controlled by `sb`. Characters are extracted and
|
|
|
|
| 522 |
inserted until any of 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);
|
|
|
|
| 540 |
Each unformatted input function begins execution by constructing an
|
| 541 |
object of class `sentry` with the default argument `noskipws` (second)
|
| 542 |
argument `true`. If the `sentry` object returns `true`, when converted
|
| 543 |
to a value of type `bool`, the function endeavors to obtain the
|
| 544 |
requested input. Otherwise, if the sentry constructor exits by throwing
|
| 545 |
+
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 `ios::badbit` is turned on[^23] in `*this`’s error
|
| 552 |
+
state. (Exceptions thrown from `basic_ios<>::clear()` are not caught or
|
| 553 |
rethrown.) If `(exceptions()&badbit) != 0` then the exception is
|
| 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.
|
|
|
|
| 559 |
``` cpp
|
| 560 |
streamsize gcount() const;
|
| 561 |
```
|
| 562 |
|
| 563 |
*Effects:* None. This member function does not behave as an unformatted
|
| 564 |
+
input function (as described above).
|
| 565 |
|
| 566 |
*Returns:* The number of characters extracted by the last unformatted
|
| 567 |
input member function called for the object.
|
| 568 |
|
| 569 |
``` cpp
|
| 570 |
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` ([[iostate.flags]]),
|
|
|
|
| 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 |
+
`ios_base::failure` ([[iostate.flags]])).
|
| 589 |
|
| 590 |
*Returns:* `*this`.
|
| 591 |
|
| 592 |
``` cpp
|
| 593 |
+
basic_istream<charT, traits>& get(char_type* s, streamsize n, char_type delim);
|
|
|
|
| 594 |
```
|
| 595 |
|
| 596 |
*Effects:* Behaves as an unformatted input function (as described
|
| 597 |
+
above). After constructing a sentry object, extracts characters and
|
| 598 |
+
stores them into successive locations of an array whose first element is
|
| 599 |
+
designated by `s`.[^25] Characters are extracted and stored until any of
|
| 600 |
+
the following occurs:
|
| 601 |
|
| 602 |
- `n` is less than one or `n - 1` characters are stored;
|
| 603 |
- end-of-file occurs on the input sequence (in which case the function
|
| 604 |
calls `setstate(eofbit)`);
|
| 605 |
- `traits::eq(c, delim)` for the next available input character `c` (in
|
|
|
|
| 614 |
|
| 615 |
``` cpp
|
| 616 |
basic_istream<charT, traits>& get(char_type* s, streamsize n);
|
| 617 |
```
|
| 618 |
|
| 619 |
+
*Effects:* Calls `get(s, n, widen(’\n’))`.
|
| 620 |
|
| 621 |
*Returns:* Value returned by the call.
|
| 622 |
|
| 623 |
``` cpp
|
| 624 |
+
basic_istream<charT, traits>& get(basic_streambuf<char_type, traits>& sb, char_type delim);
|
|
|
|
| 625 |
```
|
| 626 |
|
| 627 |
*Effects:* Behaves as an unformatted input function (as described
|
| 628 |
+
above). After constructing a sentry object, extracts characters and
|
| 629 |
+
inserts them in the output sequence controlled by `sb`. Characters are
|
| 630 |
+
extracted and inserted until any of the following occurs:
|
|
|
|
| 631 |
|
| 632 |
- end-of-file occurs on the input sequence;
|
| 633 |
- inserting in the output sequence fails (in which case the character to
|
| 634 |
be inserted is not extracted);
|
| 635 |
- `traits::eq(c, delim)` for the next available input character `c` (in
|
|
|
|
| 644 |
|
| 645 |
``` cpp
|
| 646 |
basic_istream<charT, traits>& get(basic_streambuf<char_type, traits>& sb);
|
| 647 |
```
|
| 648 |
|
| 649 |
+
*Effects:* Calls `get(sb, widen(’\n’))`.
|
| 650 |
|
| 651 |
*Returns:* Value returned by the call.
|
| 652 |
|
| 653 |
``` cpp
|
| 654 |
+
basic_istream<charT, traits>& getline(char_type* s, streamsize n, char_type delim);
|
|
|
|
| 655 |
```
|
| 656 |
|
| 657 |
*Effects:* Behaves as an unformatted input function (as described
|
| 658 |
+
above). After constructing a sentry object, extracts characters and
|
| 659 |
+
stores them into successive locations of an array whose first element is
|
| 660 |
+
designated by `s`.[^26] Characters are extracted and stored until one of
|
| 661 |
+
the following occurs:
|
| 662 |
|
| 663 |
1. end-of-file occurs on the input sequence (in which case the function
|
| 664 |
calls `setstate(eofbit)`);
|
| 665 |
2. `traits::eq(c, delim)` for the next available input character `c`
|
| 666 |
(in which case the input character is extracted but not
|
| 667 |
+
stored);[^27]
|
| 668 |
3. `n` is less than one or `n - 1` characters are stored (in which case
|
| 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` ([[iostate.flags]])).[^29]
|
| 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 |
|
| 680 |
*Returns:* `*this`.
|
| 681 |
|
| 682 |
+
[*Example 1*:
|
| 683 |
+
|
| 684 |
``` cpp
|
| 685 |
#include <iostream>
|
| 686 |
|
| 687 |
int main() {
|
| 688 |
using namespace std;
|
|
|
|
| 704 |
cout << " (" << count << " chars): " << buffer << endl;
|
| 705 |
}
|
| 706 |
}
|
| 707 |
```
|
| 708 |
|
| 709 |
+
— *end example*]
|
| 710 |
+
|
| 711 |
``` cpp
|
| 712 |
basic_istream<charT, traits>& getline(char_type* s, streamsize n);
|
| 713 |
```
|
| 714 |
|
| 715 |
*Returns:* `getline(s, n, widen(’\n’))`
|
| 716 |
|
| 717 |
``` cpp
|
| 718 |
+
basic_istream<charT, traits>& ignore(streamsize n = 1, int_type delim = traits::eof());
|
|
|
|
| 719 |
```
|
| 720 |
|
| 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()` ([[numeric.limits]]) and `n`
|
| 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 |
`ios_base::failure` ([[iostate.flags]]));
|
| 731 |
- `traits::eq_int_type(traits::to_int_type(c), delim)` for the next
|
|
|
|
| 739 |
``` cpp
|
| 740 |
int_type peek();
|
| 741 |
```
|
| 742 |
|
| 743 |
*Effects:* Behaves as an unformatted input function (as described
|
| 744 |
+
above). After constructing a sentry object, reads but does not extract
|
| 745 |
+
the current input character.
|
| 746 |
|
| 747 |
*Returns:* `traits::eof()` if `good()` is `false`. Otherwise, returns
|
| 748 |
`rdbuf()->sgetc()`.
|
| 749 |
|
| 750 |
``` cpp
|
| 751 |
basic_istream<charT, traits>& read(char_type* s, streamsize n);
|
| 752 |
```
|
| 753 |
|
| 754 |
*Effects:* Behaves as an unformatted input function (as described
|
| 755 |
+
above). After constructing a sentry object, if `!good()` calls
|
| 756 |
+
`setstate(failbit)` which may throw an exception, and return. Otherwise
|
| 757 |
+
extracts characters and stores them into successive locations of an
|
| 758 |
+
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` ([[iostate.flags]])).
|
|
|
|
| 768 |
``` cpp
|
| 769 |
streamsize readsome(char_type* s, streamsize n);
|
| 770 |
```
|
| 771 |
|
| 772 |
*Effects:* Behaves as an unformatted input function (as described
|
| 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` ([[iostate.flags]])), and extracts no characters;
|
|
|
|
| 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.
|
|
|
|
| 785 |
``` cpp
|
| 786 |
basic_istream<charT, traits>& putback(char_type c);
|
| 787 |
```
|
| 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` ([[iostate.flags]])).
|
| 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`.
|
| 801 |
|
| 802 |
``` cpp
|
| 803 |
basic_istream<charT, traits>& unget();
|
| 804 |
```
|
| 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` ([[iostate.flags]])).
|
| 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`.
|
| 818 |
|
| 819 |
``` cpp
|
| 820 |
int sync();
|
| 821 |
```
|
| 822 |
|
| 823 |
*Effects:* Behaves as an unformatted input function (as described
|
| 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` ([[iostate.flags]]), and returns `-1`. Otherwise,
|
| 830 |
returns zero.
|
| 831 |
|
| 832 |
``` cpp
|
| 833 |
pos_type tellg();
|
| 834 |
```
|
| 835 |
|
| 836 |
*Effects:* Behaves as an unformatted input function (as described
|
| 837 |
+
above), except that it does not count the number of characters extracted
|
| 838 |
+
and does not affect the value returned by subsequent calls to
|
| 839 |
+
`gcount()`.
|
| 840 |
|
| 841 |
*Returns:* After constructing a sentry object, if `fail() != false`,
|
| 842 |
returns `pos_type(-1)` to indicate failure. Otherwise, returns
|
| 843 |
`rdbuf()->pubseekoff(0, cur, in)`.
|
| 844 |
|
| 845 |
``` cpp
|
| 846 |
basic_istream<charT, traits>& seekg(pos_type pos);
|
| 847 |
```
|
| 848 |
|
| 849 |
*Effects:* Behaves as an unformatted input function (as described
|
| 850 |
+
above), except that the function first clears `eofbit`, it does not
|
| 851 |
+
count the number of characters extracted, and it does not affect the
|
| 852 |
+
value returned by subsequent calls to `gcount()`. After constructing a
|
| 853 |
+
sentry object, if `fail() != true`, executes
|
| 854 |
+
`rdbuf()->pubseekpos(pos, ios_base::in)`. In case of failure, the
|
| 855 |
+
function calls `setstate(failbit)` (which may throw
|
| 856 |
`ios_base::failure`).
|
| 857 |
|
| 858 |
*Returns:* `*this`.
|
| 859 |
|
| 860 |
``` cpp
|
| 861 |
basic_istream<charT, traits>& seekg(off_type off, ios_base::seekdir dir);
|
| 862 |
```
|
| 863 |
|
| 864 |
*Effects:* Behaves as an unformatted input function (as described
|
| 865 |
+
above), except that the function first clears `eofbit`, does not count
|
| 866 |
+
the number of characters extracted, and does not affect the value
|
| 867 |
returned by subsequent calls to `gcount()`. After constructing a sentry
|
| 868 |
object, if `fail() != true`, executes
|
| 869 |
`rdbuf()->pubseekoff(off, dir, ios_base::in)`. In case of failure, the
|
| 870 |
function calls `setstate(failbit)` (which may throw
|
| 871 |
`ios_base::failure`).
|
|
|
|
| 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 function
|
| 883 |
+
([[istream.unformatted]]), except that it does not count the number of
|
| 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` ([[istream::sentry]]). If `ws` stops extracting
|
| 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 <class charT, class traits, class T>
|
| 899 |
+
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&& is, T&& x);
|
| 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>>
|
| 917 |
+
class basic_iostream
|
| 918 |
+
: public basic_istream<charT, traits>,
|
| 919 |
public basic_ostream<charT, traits> {
|
| 920 |
public:
|
| 921 |
+
using char_type = charT;
|
| 922 |
+
using int_type = typename traits::int_type;
|
| 923 |
+
using pos_type = typename traits::pos_type;
|
| 924 |
+
using off_type = typename traits::off_type;
|
| 925 |
+
using traits_type = traits;
|
|
|
|
| 926 |
|
| 927 |
+
// [iostream.cons], constructor
|
| 928 |
explicit basic_iostream(basic_streambuf<charT, traits>* sb);
|
| 929 |
+
|
| 930 |
+
// [iostream.dest], destructor
|
| 931 |
virtual ~basic_iostream();
|
| 932 |
|
| 933 |
protected:
|
| 934 |
+
// [iostream.cons], constructor
|
| 935 |
basic_iostream(const basic_iostream& rhs) = delete;
|
| 936 |
basic_iostream(basic_iostream&& rhs);
|
| 937 |
|
| 938 |
+
// [iostream.assign], assign and swap
|
| 939 |
basic_iostream& operator=(const basic_iostream& rhs) = delete;
|
| 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 |
##### `basic_iostream` constructors <a id="iostream.cons">[[iostream.cons]]</a>
|
| 951 |
|
| 952 |
``` cpp
|
| 953 |
explicit basic_iostream(basic_streambuf<charT, traits>* sb);
|
| 954 |
```
|
| 955 |
|
| 956 |
+
*Effects:* Constructs an object of class `basic_iostream`, initializing
|
| 957 |
+
the base class subobjects with
|
| 958 |
`basic_istream<charT, traits>(sb)` ([[istream]]) and
|
| 959 |
+
`basic_ostream<charT, traits>(sb)` ([[ostream]]).
|
| 960 |
|
| 961 |
+
*Postconditions:* `rdbuf() == sb` and `gcount() == 0`.
|
| 962 |
|
| 963 |
``` cpp
|
| 964 |
basic_iostream(basic_iostream&& rhs);
|
| 965 |
```
|
| 966 |
|
|
|
|
| 981 |
|
| 982 |
``` cpp
|
| 983 |
basic_iostream& operator=(basic_iostream&& rhs);
|
| 984 |
```
|
| 985 |
|
| 986 |
+
*Effects:* As if by `swap(rhs)`.
|
| 987 |
|
| 988 |
``` cpp
|
| 989 |
void swap(basic_iostream& rhs);
|
| 990 |
```
|
| 991 |
|
| 992 |
*Effects:* Calls `basic_istream<charT, traits>::swap(rhs)`.
|
| 993 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 994 |
### Output streams <a id="output.streams">[[output.streams]]</a>
|
| 995 |
|
| 996 |
The header `<ostream>` defines a type and several function signatures
|
| 997 |
that control output to a stream buffer along with a function template
|
| 998 |
that inserts into stream rvalues.
|
|
|
|
| 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>&));
|
| 1024 |
+
basic_ostream<charT, traits>&
|
| 1025 |
+
operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));
|
| 1026 |
+
basic_ostream<charT, traits>&
|
| 1027 |
+
operator<<(ios_base& (*pf)(ios_base&));
|
| 1028 |
|
| 1029 |
basic_ostream<charT, traits>& operator<<(bool n);
|
| 1030 |
basic_ostream<charT, traits>& operator<<(short n);
|
| 1031 |
basic_ostream<charT, traits>& operator<<(unsigned short n);
|
| 1032 |
basic_ostream<charT, traits>& operator<<(int n);
|
|
|
|
| 1038 |
basic_ostream<charT, traits>& operator<<(float f);
|
| 1039 |
basic_ostream<charT, traits>& operator<<(double f);
|
| 1040 |
basic_ostream<charT, traits>& operator<<(long double f);
|
| 1041 |
|
| 1042 |
basic_ostream<charT, traits>& operator<<(const void* p);
|
| 1043 |
+
basic_ostream<charT, traits>& operator<<(nullptr_t);
|
| 1044 |
+
basic_ostream<charT, traits>& operator<<(basic_streambuf<char_type, traits>* sb);
|
| 1045 |
|
| 1046 |
+
// [ostream.unformatted], unformatted output
|
| 1047 |
basic_ostream<charT, traits>& put(char_type c);
|
| 1048 |
basic_ostream<charT, traits>& write(const char_type* s, streamsize n);
|
| 1049 |
|
| 1050 |
basic_ostream<charT, traits>& flush();
|
| 1051 |
|
| 1052 |
+
// [ostream.seeks], seeks
|
| 1053 |
pos_type tellp();
|
| 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& rhs) = delete;
|
| 1060 |
basic_ostream(basic_ostream&& rhs);
|
| 1061 |
|
| 1062 |
+
// [ostream.assign], assign and swap
|
| 1063 |
basic_ostream& operator=(const basic_ostream& rhs) = delete;
|
| 1064 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 1065 |
void swap(basic_ostream& rhs);
|
| 1066 |
};
|
| 1067 |
|
| 1068 |
+
// [ostream.inserters.character], character inserters
|
| 1069 |
template<class charT, class traits>
|
| 1070 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, charT);
|
|
|
|
| 1071 |
template<class charT, class traits>
|
| 1072 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, char);
|
|
|
|
| 1073 |
template<class traits>
|
| 1074 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char);
|
|
|
|
| 1075 |
|
|
|
|
| 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>
|
| 1086 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char*);
|
|
|
|
| 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
|
| 1097 |
+
sequences controlled by a stream buffer.
|
| 1098 |
|
| 1099 |
Two groups of member function signatures share common properties: the
|
| 1100 |
*formatted output functions* (or *inserters*) and the *unformatted
|
| 1101 |
output functions.* Both groups of output functions generate (or
|
| 1102 |
*insert*) output *characters* by actions equivalent to calling
|
|
|
|
| 1108 |
explicitly noted otherwise the output function sets `badbit` in error
|
| 1109 |
state. If `badbit` is on in `exceptions()`, the output function rethrows
|
| 1110 |
the exception without completing its actions, otherwise it does not
|
| 1111 |
throw anything and treat as an error.
|
| 1112 |
|
| 1113 |
+
##### `basic_ostream` constructors <a id="ostream.cons">[[ostream.cons]]</a>
|
| 1114 |
|
| 1115 |
``` cpp
|
| 1116 |
explicit basic_ostream(basic_streambuf<charT, traits>* sb);
|
| 1117 |
```
|
| 1118 |
|
| 1119 |
+
*Effects:* Constructs an object of class `basic_ostream`, initializing
|
| 1120 |
+
the base class subobject with
|
| 1121 |
+
`basic_ios<charT, traits>::init(sb)` ([[basic.ios.cons]]).
|
| 1122 |
+
|
| 1123 |
+
*Postconditions:* `rdbuf() == sb`.
|
| 1124 |
|
| 1125 |
``` cpp
|
| 1126 |
basic_ostream(basic_ostream&& rhs);
|
| 1127 |
```
|
| 1128 |
|
| 1129 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 1130 |
by default constructing the base class and calling
|
| 1131 |
`basic_ios<charT, traits>::move(rhs)` to initialize the base class.
|
| 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 |
+
##### Class `basic_ostream` assign and swap <a id="ostream.assign">[[ostream.assign]]</a>
|
| 1142 |
|
| 1143 |
``` cpp
|
| 1144 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 1145 |
```
|
| 1146 |
|
| 1147 |
+
*Effects:* As if by `swap(rhs)`.
|
| 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::sentry">[[ostream::sentry]]</a>
|
| 1158 |
|
| 1159 |
``` cpp
|
| 1160 |
namespace std {
|
| 1161 |
template <class charT, class traits = char_traits<charT>>
|
| 1162 |
class basic_ostream<charT, traits>::sentry {
|
|
|
|
| 1178 |
``` cpp
|
| 1179 |
explicit sentry(basic_ostream<charT, traits>& os);
|
| 1180 |
```
|
| 1181 |
|
| 1182 |
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` ([[iostate.flags]]))[^32]
|
| 1189 |
|
| 1190 |
``` cpp
|
| 1191 |
~sentry();
|
| 1192 |
```
|
| 1193 |
|
| 1194 |
If
|
| 1195 |
+
`(os.flags() & ios_base::unitbuf) && !uncaught_exceptions() && os.good()`
|
| 1196 |
is `true`, calls `os.rdbuf()->pubsync()`. If that function returns -1,
|
| 1197 |
sets `badbit` in `os.rdstate()` without propagating an exception.
|
| 1198 |
|
| 1199 |
``` cpp
|
| 1200 |
explicit operator bool() const;
|
| 1201 |
```
|
| 1202 |
|
| 1203 |
*Effects:* Returns `ok_`.
|
| 1204 |
|
| 1205 |
+
##### `basic_ostream` seek members <a id="ostream.seeks">[[ostream.seeks]]</a>
|
| 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
|
| 1211 |
pos_type tellp();
|
| 1212 |
```
|
| 1213 |
|
| 1214 |
+
*Returns:* If `fail() != false`, returns `pos_type(-1)` to indicate
|
| 1215 |
+
failure. Otherwise, returns `rdbuf()->pubseekoff(0, cur, out)`.
|
| 1216 |
+
|
| 1217 |
``` cpp
|
| 1218 |
basic_ostream<charT, traits>& seekp(pos_type pos);
|
| 1219 |
```
|
| 1220 |
|
| 1221 |
+
*Effects:* If `fail() != true`, executes
|
| 1222 |
+
`rdbuf()->pubseekpos(pos, ios_base::out)`. In case of failure, the
|
| 1223 |
+
function calls `setstate(failbit)` (which may throw
|
| 1224 |
+
`ios_base::failure`).
|
| 1225 |
+
|
| 1226 |
+
*Returns:* `*this`.
|
| 1227 |
+
|
| 1228 |
``` cpp
|
| 1229 |
basic_ostream<charT, traits>& seekp(off_type off, ios_base::seekdir dir);
|
| 1230 |
```
|
| 1231 |
|
| 1232 |
*Effects:* If `fail() != true`, executes
|
|
|
|
| 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 `ios::badbit`
|
| 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 |
|
|
|
|
| 1345 |
The first argument provides an object of the `ostreambuf_iterator<>`
|
| 1346 |
class which is an iterator for class `basic_ostream<>`. It bypasses
|
| 1347 |
`ostream`s and uses `streambuf`s directly. Class `locale` relies on
|
| 1348 |
these types as its interface to iostreams, since for flexibility it has
|
| 1349 |
been abstracted away from direct dependence on `ostream`. The second
|
| 1350 |
+
parameter is a reference to the base class subobject of type `ios_base`.
|
| 1351 |
+
It provides formatting specifications such as field width, and a locale
|
| 1352 |
from which to obtain other facets. If `failed` is `true` then does
|
| 1353 |
`setstate(badbit)`, which may throw an exception, and returns.
|
| 1354 |
|
| 1355 |
*Returns:* `*this`.
|
| 1356 |
|
| 1357 |
##### `basic_ostream::operator<<` <a id="ostream.inserters">[[ostream.inserters]]</a>
|
| 1358 |
|
| 1359 |
``` cpp
|
| 1360 |
+
basic_ostream<charT, traits>&
|
| 1361 |
+
operator<<(basic_ostream<charT, traits>& (*pf)(basic_ostream<charT, traits>&));
|
| 1362 |
```
|
| 1363 |
|
| 1364 |
*Effects:* None. Does not behave as a formatted output function (as
|
| 1365 |
described in [[ostream.formatted.reqmts]]).
|
| 1366 |
|
| 1367 |
+
*Returns:* `pf(*this)`.[^34]
|
| 1368 |
|
| 1369 |
``` cpp
|
| 1370 |
+
basic_ostream<charT, traits>&
|
| 1371 |
+
operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));
|
| 1372 |
```
|
| 1373 |
|
| 1374 |
*Effects:* Calls `pf(*this)`. This inserter does not behave as a
|
| 1375 |
formatted output function (as described
|
| 1376 |
in [[ostream.formatted.reqmts]]).
|
| 1377 |
|
| 1378 |
+
*Returns:* `*this`.[^35]
|
| 1379 |
|
| 1380 |
``` cpp
|
| 1381 |
+
basic_ostream<charT, traits>& operator<<(ios_base& (*pf)(ios_base&));
|
|
|
|
| 1382 |
```
|
| 1383 |
|
| 1384 |
*Effects:* Calls `pf(*this)`. This inserter does not behave as a
|
| 1385 |
formatted output function (as described
|
| 1386 |
in [[ostream.formatted.reqmts]]).
|
| 1387 |
|
| 1388 |
*Returns:* `*this`.
|
| 1389 |
|
| 1390 |
``` cpp
|
| 1391 |
+
basic_ostream<charT, traits>& operator<<(basic_streambuf<charT, traits>* sb);
|
|
|
|
| 1392 |
```
|
| 1393 |
|
| 1394 |
+
*Effects:* Behaves as an unformatted output function
|
| 1395 |
+
([[ostream.unformatted]]). After the sentry object is constructed, if
|
| 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 |
|
|
|
|
| 1410 |
`failbit` in error state, and if `failbit` is on in `exceptions()` the
|
| 1411 |
caught exception is rethrown.
|
| 1412 |
|
| 1413 |
*Returns:* `*this`.
|
| 1414 |
|
| 1415 |
+
``` cpp
|
| 1416 |
+
basic_ostream<charT, traits>& operator<<(nullptr_t);
|
| 1417 |
+
```
|
| 1418 |
+
|
| 1419 |
+
*Effects:* Equivalent to:
|
| 1420 |
+
|
| 1421 |
+
``` cpp
|
| 1422 |
+
return *this << s;
|
| 1423 |
+
```
|
| 1424 |
+
|
| 1425 |
+
where `s` is an *implementation-defined* NTCTS ([[defns.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>
|
| 1431 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, charT c);
|
|
|
|
| 1432 |
template<class charT, class traits>
|
| 1433 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, char c);
|
|
|
|
| 1434 |
// specialization
|
| 1435 |
template<class traits>
|
| 1436 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, char c);
|
|
|
|
| 1437 |
// signed and unsigned
|
| 1438 |
template<class traits>
|
| 1439 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, signed char c);
|
|
|
|
| 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 ([[ostream.formatted.reqmts]]) of `out`. Constructs a
|
| 1446 |
+
character sequence `seq`. If `c` has type `char` and the character type
|
| 1447 |
+
of the stream is not `char`, then `seq` consists of `out.widen(c)`;
|
| 1448 |
+
otherwise `seq` consists of `c`. Determines padding for `seq` as
|
| 1449 |
+
described in [[ostream.formatted.reqmts]]. Inserts `seq` into `out`.
|
| 1450 |
+
Calls `os.width(0)`.
|
| 1451 |
|
| 1452 |
*Returns:* `out`.
|
| 1453 |
|
| 1454 |
``` cpp
|
| 1455 |
template<class charT, class traits>
|
| 1456 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, const charT* s);
|
|
|
|
| 1457 |
template<class charT, class traits>
|
| 1458 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, const char* s);
|
|
|
|
| 1459 |
template<class traits>
|
| 1460 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, const char* s);
|
|
|
|
| 1461 |
template<class traits>
|
| 1462 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, const signed char* s);
|
|
|
|
| 1463 |
template<class traits>
|
| 1464 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out,
|
| 1465 |
const unsigned char* s);
|
| 1466 |
```
|
| 1467 |
|
|
|
|
| 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
|
| 1480 |
`const char*`,
|
| 1481 |
+
- `char_traits<char>::length(s)` for the overload where the first
|
| 1482 |
argument is of type `basic_ostream<charT, traits>&` and the second is
|
| 1483 |
of type `const char*`,
|
| 1484 |
- `traits::length(reinterpret_cast<const char*>(s))` for the other two
|
| 1485 |
overloads.
|
| 1486 |
|
|
|
|
| 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 |
+
`ios::badbit` is turned on[^36] in `*this`’s error state. If
|
| 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 |
|
| 1505 |
``` cpp
|
| 1506 |
basic_ostream<charT, traits>& put(char_type c);
|
| 1507 |
```
|
| 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 |
`ios_base::failure` ([[iostate.flags]])).
|
| 1515 |
|
| 1516 |
*Returns:* `*this`.
|
|
|
|
| 1518 |
``` cpp
|
| 1519 |
basic_ostream& write(const char_type* s, streamsize n);
|
| 1520 |
```
|
| 1521 |
|
| 1522 |
*Effects:* Behaves as an unformatted output function (as described
|
| 1523 |
+
above). After constructing a sentry object, obtains characters to insert
|
| 1524 |
+
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 |
`ios_base::failure` ([[iostate.flags]])).
|
|
|
|
| 1535 |
``` cpp
|
| 1536 |
basic_ostream& flush();
|
| 1537 |
```
|
| 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 |
`ios_base::failure` ([[iostate.flags]])). Otherwise, if the sentry
|
| 1545 |
object returns `false`, does nothing.
|
| 1546 |
|
| 1547 |
*Returns:* `*this`.
|
| 1548 |
|
| 1549 |
#### Standard `basic_ostream` manipulators <a id="ostream.manip">[[ostream.manip]]</a>
|
| 1550 |
|
| 1551 |
``` cpp
|
|
|
|
| 1552 |
template <class charT, class traits>
|
| 1553 |
basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);
|
|
|
|
| 1554 |
```
|
| 1555 |
|
| 1556 |
*Effects:* Calls `os.put(os.widen(’\n’))`, then `os.flush()`.
|
| 1557 |
|
| 1558 |
*Returns:* `os`.
|
| 1559 |
|
| 1560 |
``` cpp
|
|
|
|
| 1561 |
template <class charT, class traits>
|
| 1562 |
basic_ostream<charT, traits>& ends(basic_ostream<charT, traits>& os);
|
|
|
|
| 1563 |
```
|
| 1564 |
|
| 1565 |
*Effects:* Inserts a null character into the output sequence: calls
|
| 1566 |
`os.put(charT())`.
|
| 1567 |
|
| 1568 |
*Returns:* `os`.
|
| 1569 |
|
| 1570 |
``` cpp
|
|
|
|
| 1571 |
template <class charT, class traits>
|
| 1572 |
basic_ostream<charT, traits>& flush(basic_ostream<charT, traits>& os);
|
|
|
|
| 1573 |
```
|
| 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 <class charT, class traits, class T>
|
| 1583 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&& os, const T& x);
|
|
|
|
| 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
|
|
|
|
| 1600 |
unspecified resetiosflags(ios_base::fmtflags mask);
|
| 1601 |
```
|
| 1602 |
|
| 1603 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1604 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1605 |
+
`out << resetiosflags(mask)` behaves as if it called `f(out, mask)`, or
|
| 1606 |
if `in` is an object of type `basic_istream<charT, traits>` then the
|
| 1607 |
+
expression `in >> resetiosflags(mask)` behaves as if it called
|
| 1608 |
+
`f(in, mask)`, where the function `f` is defined as:[^39]
|
| 1609 |
|
| 1610 |
``` cpp
|
| 1611 |
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)` shall have type
|
| 1618 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1619 |
+
`in >> resetiosflags(mask)` shall have type
|
| 1620 |
`basic_istream<charT, traits>&` and value `in`.
|
| 1621 |
|
| 1622 |
``` cpp
|
| 1623 |
unspecified setiosflags(ios_base::fmtflags mask);
|
| 1624 |
```
|
| 1625 |
|
| 1626 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1627 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1628 |
+
`out << setiosflags(mask)` behaves as if it called `f(out, mask)`, or if
|
| 1629 |
`in` is an object of type `basic_istream<charT, traits>` then the
|
| 1630 |
+
expression `in >> setiosflags(mask)` behaves as if it called
|
| 1631 |
`f(in, mask)`, where the function `f` is defined as:
|
| 1632 |
|
| 1633 |
``` cpp
|
| 1634 |
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)` shall have type
|
| 1641 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1642 |
+
`in >> setiosflags(mask)` shall have type `basic_istream<charT,`
|
| 1643 |
`traits>&` and value `in`.
|
| 1644 |
|
| 1645 |
``` cpp
|
| 1646 |
unspecified setbase(int base);
|
| 1647 |
```
|
| 1648 |
|
| 1649 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1650 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1651 |
+
`out << setbase(base)` behaves as if it called `f(out, base)`, or if
|
| 1652 |
`in` is an object of type `basic_istream<charT, traits>` then the
|
| 1653 |
+
expression `in >> setbase(base)` behaves as if it called `f(in, base)`,
|
| 1654 |
where the function `f` is defined as:
|
| 1655 |
|
| 1656 |
``` cpp
|
| 1657 |
void f(ios_base& str, int base) {
|
| 1658 |
// set basefield
|
|
|
|
| 1661 |
base == 16 ? ios_base::hex :
|
| 1662 |
ios_base::fmtflags(0), ios_base::basefield);
|
| 1663 |
}
|
| 1664 |
```
|
| 1665 |
|
| 1666 |
+
The expression `out << setbase(base)` shall have type
|
| 1667 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1668 |
+
`in >> setbase(base)` shall have type `basic_istream<charT, traits>&`
|
| 1669 |
and value `in`.
|
| 1670 |
|
| 1671 |
``` cpp
|
| 1672 |
unspecified setfill(char_type c);
|
| 1673 |
```
|
| 1674 |
|
| 1675 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1676 |
of type `basic_ostream<charT, traits>` and `c` has type `charT` then the
|
| 1677 |
+
expression `out << setfill(c)` behaves as if it called `f(out, c)`,
|
| 1678 |
where the function `f` is defined as:
|
| 1679 |
|
| 1680 |
``` cpp
|
| 1681 |
template<class charT, class traits>
|
| 1682 |
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)` shall have type
|
| 1689 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1690 |
|
| 1691 |
``` cpp
|
| 1692 |
unspecified setprecision(int n);
|
| 1693 |
```
|
| 1694 |
|
| 1695 |
*Returns:* An object of unspecified type such that if `out` is an object
|
| 1696 |
of type `basic_ostream<charT, traits>` then the expression
|
| 1697 |
+
`out << setprecision(n)` behaves as if it called `f(out, n)`, or if `in`
|
| 1698 |
is an object of type `basic_istream<charT, traits>` then the expression
|
| 1699 |
+
`in >> setprecision(n)` behaves as if it called `f(in, n)`, where the
|
| 1700 |
function `f` is defined as:
|
| 1701 |
|
| 1702 |
``` cpp
|
| 1703 |
void f(ios_base& str, int n) {
|
| 1704 |
// set precision
|
| 1705 |
str.precision(n);
|
| 1706 |
}
|
| 1707 |
```
|
| 1708 |
|
| 1709 |
+
The expression `out << setprecision(n)` shall have type
|
| 1710 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1711 |
+
`in >> setprecision(n)` shall have type `basic_istream<charT, traits>&`
|
| 1712 |
and value `in`.
|
| 1713 |
|
| 1714 |
``` cpp
|
| 1715 |
unspecified setw(int n);
|
| 1716 |
```
|
| 1717 |
|
| 1718 |
*Returns:* An object of unspecified type such that if `out` is an
|
| 1719 |
instance of `basic_ostream<charT, traits>` then the expression
|
| 1720 |
+
`out << setw(n)` behaves as if it called `f(out, n)`, or if `in` is an
|
| 1721 |
object of type `basic_istream<charT, traits>` then the expression
|
| 1722 |
+
`in >> setw(n)` behaves as if it called `f(in, n)`, where the function
|
| 1723 |
`f` is defined as:
|
| 1724 |
|
| 1725 |
``` cpp
|
| 1726 |
void f(ios_base& str, int n) {
|
| 1727 |
// set width
|
| 1728 |
str.width(n);
|
| 1729 |
}
|
| 1730 |
```
|
| 1731 |
|
| 1732 |
+
The expression `out << setw(n)` shall have type
|
| 1733 |
`basic_ostream<charT, traits>&` and value `out`. The expression
|
| 1734 |
+
`in >> setw(n)` shall have type `basic_istream<charT, traits>&` and
|
| 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
|
|
|
|
| 1750 |
*Effects:* The expression `in >> get_money(mon, intl)` described below
|
| 1751 |
behaves as a formatted input function ([[istream.formatted.reqmts]]).
|
| 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:
|
| 1757 |
|
| 1758 |
``` cpp
|
| 1759 |
template <class charT, class traits, class moneyT>
|
| 1760 |
void f(basic_ios<charT, traits>& str, moneyT& mon, bool intl) {
|
| 1761 |
+
using Iter = istreambuf_iterator<charT, traits>;
|
| 1762 |
+
using MoneyGet = money_get<charT, Iter>;
|
| 1763 |
|
| 1764 |
ios_base::iostate err = ios_base::goodbit;
|
| 1765 |
const MoneyGet& mg = use_facet<MoneyGet>(str.getloc());
|
| 1766 |
|
| 1767 |
mg.get(Iter(str.rdbuf()), Iter(), intl, str, err, mon);
|
|
|
|
| 1769 |
if (ios_base::goodbit != err)
|
| 1770 |
str.setstate(err);
|
| 1771 |
}
|
| 1772 |
```
|
| 1773 |
|
| 1774 |
+
The expression `in >> get_money(mon, intl)` shall have type
|
| 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 |
```
|
|
|
|
| 1781 |
*Requires:* The type `moneyT` shall be either `long double` or a
|
| 1782 |
specialization of the `basic_string` template (Clause [[strings]]).
|
| 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 ([[ostream.formatted.reqmts]]) that calls `f(out, mon, intl)`,
|
| 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) {
|
| 1793 |
+
using Iter = ostreambuf_iterator<charT, traits>;
|
| 1794 |
+
using MoneyPut = money_put<charT, Iter>;
|
| 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(ios::badbit);
|
| 1801 |
}
|
| 1802 |
```
|
| 1803 |
|
| 1804 |
+
The expression `out << put_money(mon, intl)` shall have type
|
| 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 |
*Requires:* The argument `tmb` shall be a valid pointer to an object of
|
| 1812 |
+
type `struct tm`. The argument `fmt` shall be a valid pointer to an
|
| 1813 |
array of objects of type `charT` with `char_traits<charT>::length(fmt)`
|
| 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:
|
| 1820 |
|
| 1821 |
``` cpp
|
| 1822 |
template <class charT, class traits>
|
| 1823 |
void f(basic_ios<charT, traits>& str, struct tm* tmb, const charT* fmt) {
|
| 1824 |
+
using Iter = istreambuf_iterator<charT, traits>;
|
| 1825 |
+
using TimeGet = time_get<charT, Iter>;
|
| 1826 |
|
| 1827 |
ios_base::iostate err = ios_base::goodbit;
|
| 1828 |
const TimeGet& tg = use_facet<TimeGet>(str.getloc());
|
| 1829 |
|
| 1830 |
tg.get(Iter(str.rdbuf()), Iter(), str, err, tmb,
|
| 1831 |
fmt, fmt + traits::length(fmt));
|
| 1832 |
|
| 1833 |
if (err != ios_base::goodbit)
|
| 1834 |
+
str.setstate(err);
|
| 1835 |
}
|
| 1836 |
```
|
| 1837 |
|
| 1838 |
+
The expression `in >> get_time(tmb, fmt)` shall have type
|
| 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 |
```
|
|
|
|
| 1847 |
array of objects of type `charT` with `char_traits<charT>::length(fmt)`
|
| 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:
|
| 1854 |
|
| 1855 |
``` cpp
|
| 1856 |
template <class charT, class traits>
|
| 1857 |
void f(basic_ios<charT, traits>& str, const struct tm* tmb, const charT* fmt) {
|
| 1858 |
+
using Iter = ostreambuf_iterator<charT, traits>;
|
| 1859 |
+
using TimePut = time_put<charT, Iter>;
|
| 1860 |
|
| 1861 |
const TimePut& tp = use_facet<TimePut>(str.getloc());
|
| 1862 |
const Iter end = tp.put(Iter(str.rdbuf()), str, str.fill(), tmb,
|
| 1863 |
fmt, fmt + traits::length(fmt));
|
| 1864 |
|
| 1865 |
if (end.failed())
|
| 1866 |
str.setstate(ios_base::badbit);
|
| 1867 |
}
|
| 1868 |
```
|
| 1869 |
|
| 1870 |
+
The expression `out << put_time(tmb, fmt)` shall have type
|
| 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
|
| 1876 |
+
of quoted strings (for example, XML and CSV formats). Quoted
|
| 1877 |
+
manipulators are useful in ensuring that the content of a string with
|
| 1878 |
+
embedded spaces remains unchanged if inserted and then extracted via
|
| 1879 |
+
stream I/O. — *end note*]
|
| 1880 |
|
| 1881 |
``` cpp
|
| 1882 |
template <class charT>
|
| 1883 |
unspecified quoted(const charT* s, charT delim = charT('"'), charT escape = charT('\\'));
|
| 1884 |
template <class charT, class traits, class Allocator>
|
| 1885 |
unspecified quoted(const basic_string<charT, traits, Allocator>& s,
|
| 1886 |
+
\itcorr charT delim = charT('"'), charT escape = charT('\\'));
|
| 1887 |
+
template <class charT, class traits>
|
| 1888 |
+
unspecified quoted(basic_string_view<charT, traits> s,
|
| 1889 |
+
\itcorr charT delim = charT('"'), charT escape = charT('\\'));
|
| 1890 |
```
|
| 1891 |
|
| 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 ([[ostream.formatted.reqmts]]) of `out`. This forms a
|
| 1898 |
character sequence `seq`, initially consisting of the following
|
| 1899 |
elements:
|
| 1900 |
|
| 1901 |
- `delim`.
|
|
|
|
| 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)` shall have type
|
| 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,
|
| 1917 |
+
\itcorr charT delim = charT('"'), charT escape = charT('\\'));
|
| 1918 |
```
|
| 1919 |
|
| 1920 |
*Returns:* An object of unspecified type such that:
|
| 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&)` ([[istream.extractors]])
|
| 1927 |
+
which may throw `ios_base::failure` ([[ios::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
|
| 1933 |
characters from `in` and append them to `s`, except that if an
|
| 1934 |
`escape` is reached, ignore it and append the next character to
|
| 1935 |
`s`.
|
| 1936 |
- Discard the final `delim` character.
|
| 1937 |
- Restore the `skipws` flag to its original value.
|
| 1938 |
+
- Otherwise, `in >> s`.
|
| 1939 |
- If `out` is an instance of `basic_ostream` with member types
|
| 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 |
+
The expression `in >> quoted(s, delim, escape)` shall have type
|
| 1947 |
`basic_istream<charT, traits>&` and value `in`. The expression
|
| 1948 |
+
`out << quoted(s, delim, escape)` shall have type
|
| 1949 |
`basic_ostream<charT, traits>&` and value `out`.
|
| 1950 |
|