- tmp/tmpahkkqdv_/{from.md → to.md} +235 -498
tmp/tmpahkkqdv_/{from.md → to.md}
RENAMED
|
@@ -1,93 +1,103 @@
|
|
| 1 |
## File-based streams <a id="file.streams">[[file.streams]]</a>
|
| 2 |
|
| 3 |
-
###
|
| 4 |
-
|
| 5 |
-
The header `<fstream>` defines four class templates and eight types that
|
| 6 |
-
associate stream buffers with files and assist reading and writing
|
| 7 |
-
files.
|
| 8 |
|
| 9 |
``` cpp
|
| 10 |
namespace std {
|
| 11 |
template <class charT, class traits = char_traits<charT>>
|
| 12 |
class basic_filebuf;
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
template <class charT, class traits = char_traits<charT>>
|
| 17 |
class basic_ifstream;
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
template <class charT, class traits = char_traits<charT>>
|
| 22 |
class basic_ofstream;
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
template <class charT, class traits = char_traits<charT>>
|
| 27 |
class basic_fstream;
|
| 28 |
-
|
| 29 |
-
|
| 30 |
}
|
| 31 |
```
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
-
The class template `basic_filebuf` treats a file as a source
|
| 37 |
-
bytes. In an environment that uses a large character set, the
|
| 38 |
-
typically holds multibyte character sequences and the
|
| 39 |
-
object converts those multibyte sequences into wide
|
|
|
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
namespace std {
|
| 45 |
template <class charT, class traits = char_traits<charT>>
|
| 46 |
class basic_filebuf : public basic_streambuf<charT, traits> {
|
| 47 |
public:
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
-
// [filebuf.cons]
|
| 55 |
basic_filebuf();
|
| 56 |
basic_filebuf(const basic_filebuf& rhs) = delete;
|
| 57 |
basic_filebuf(basic_filebuf&& rhs);
|
| 58 |
virtual ~basic_filebuf();
|
| 59 |
|
| 60 |
-
// [filebuf.assign]
|
| 61 |
basic_filebuf& operator=(const basic_filebuf& rhs) = delete;
|
| 62 |
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 63 |
void swap(basic_filebuf& rhs);
|
| 64 |
|
| 65 |
-
|
| 66 |
bool is_open() const;
|
| 67 |
-
basic_filebuf
|
|
|
|
|
|
|
|
|
|
| 68 |
ios_base::openmode mode);
|
| 69 |
-
basic_filebuf
|
| 70 |
ios_base::openmode mode);
|
| 71 |
-
basic_filebuf
|
| 72 |
|
| 73 |
protected:
|
| 74 |
-
// [filebuf.virtuals]
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
};
|
| 90 |
|
| 91 |
template <class charT, class traits>
|
| 92 |
void swap(basic_filebuf<charT, traits>& x,
|
| 93 |
basic_filebuf<charT, traits>& y);
|
|
@@ -97,23 +107,23 @@ namespace std {
|
|
| 97 |
The class `basic_filebuf<charT, traits>` associates both the input
|
| 98 |
sequence and the output sequence with a file.
|
| 99 |
|
| 100 |
The restrictions on reading and writing a sequence controlled by an
|
| 101 |
object of class `basic_filebuf<charT, traits>` are the same as for
|
| 102 |
-
reading and writing with the
|
| 103 |
|
| 104 |
In particular:
|
| 105 |
|
| 106 |
- If the file is not open for reading the input sequence cannot be read.
|
| 107 |
- If the file is not open for writing the output sequence cannot be
|
| 108 |
written.
|
| 109 |
- A joint file position is maintained for both the input sequence and
|
| 110 |
the output sequence.
|
| 111 |
|
| 112 |
An instance of `basic_filebuf` behaves as described in [[filebuf]]
|
| 113 |
-
provided `traits::pos_type` is `fpos<traits::state_type>`. Otherwise
|
| 114 |
-
behavior is undefined.
|
| 115 |
|
| 116 |
In order to support file I/O and multibyte/wide character conversion,
|
| 117 |
conversions are performed using members of a facet, referred to as
|
| 118 |
`a_codecvt` in following sections, obtained as if by
|
| 119 |
|
|
@@ -130,11 +140,11 @@ basic_filebuf();
|
|
| 130 |
|
| 131 |
*Effects:* Constructs an object of class `basic_filebuf<charT, traits>`,
|
| 132 |
initializing the base class with
|
| 133 |
`basic_streambuf<charT, traits>()` ([[streambuf.cons]]).
|
| 134 |
|
| 135 |
-
`is_open() == false`.
|
| 136 |
|
| 137 |
``` cpp
|
| 138 |
basic_filebuf(basic_filebuf&& rhs);
|
| 139 |
```
|
| 140 |
|
|
@@ -177,13 +187,13 @@ rethrown (see [[res.on.exception.handling]]).
|
|
| 177 |
|
| 178 |
``` cpp
|
| 179 |
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 180 |
```
|
| 181 |
|
| 182 |
-
*Effects:* Calls `
|
| 183 |
-
|
| 184 |
-
|
| 185 |
|
| 186 |
*Returns:* `*this`.
|
| 187 |
|
| 188 |
``` cpp
|
| 189 |
void swap(basic_filebuf& rhs);
|
|
@@ -195,11 +205,11 @@ void swap(basic_filebuf& rhs);
|
|
| 195 |
template <class charT, class traits>
|
| 196 |
void swap(basic_filebuf<charT, traits>& x,
|
| 197 |
basic_filebuf<charT, traits>& y);
|
| 198 |
```
|
| 199 |
|
| 200 |
-
*Effects:* `x.swap(y)`.
|
| 201 |
|
| 202 |
#### Member functions <a id="filebuf.members">[[filebuf.members]]</a>
|
| 203 |
|
| 204 |
``` cpp
|
| 205 |
bool is_open() const;
|
|
@@ -207,18 +217,19 @@ bool is_open() const;
|
|
| 207 |
|
| 208 |
*Returns:* `true` if a previous call to `open` succeeded (returned a
|
| 209 |
non-null value) and there has been no intervening call to close.
|
| 210 |
|
| 211 |
``` cpp
|
| 212 |
-
basic_filebuf
|
| 213 |
-
|
|
|
|
| 214 |
```
|
| 215 |
|
| 216 |
*Effects:* If `is_open() != false`, returns a null pointer. Otherwise,
|
| 217 |
initializes the `filebuf` as required. It then opens a file, if
|
| 218 |
possible, whose name is the NTBS`s` (as if by calling
|
| 219 |
-
`
|
| 220 |
`mode & ~ios_base::ate` as indicated in
|
| 221 |
Table [[tab:iostreams.file.open.modes]]. If `mode` is not some
|
| 222 |
combination of flags shown in the table then the open fails.
|
| 223 |
|
| 224 |
**Table: File open modes** <a id="tab:iostreams.file.open.modes">[tab:iostreams.file.open.modes]</a>
|
|
@@ -244,67 +255,67 @@ combination of flags shown in the table then the open fails.
|
|
| 244 |
| + | + | | | + | `"a+b"` |
|
| 245 |
|
| 246 |
|
| 247 |
If the open operation succeeds and `(mode & ios_base::ate) != 0`,
|
| 248 |
positions the file to the end (as if by calling
|
| 249 |
-
`
|
| 250 |
|
| 251 |
If the repositioning operation fails, calls `close()` and returns a null
|
| 252 |
pointer to indicate failure.
|
| 253 |
|
| 254 |
*Returns:* `this` if successful, a null pointer otherwise.
|
| 255 |
|
| 256 |
``` cpp
|
| 257 |
-
basic_filebuf
|
| 258 |
-
|
| 259 |
```
|
| 260 |
|
| 261 |
*Returns:* `open(s.c_str(), mode);`
|
| 262 |
|
| 263 |
``` cpp
|
| 264 |
-
basic_filebuf
|
| 265 |
```
|
| 266 |
|
| 267 |
*Effects:* If `is_open() == false`, returns a null pointer. If a put
|
| 268 |
area exists, calls `overflow(traits::eof())` to flush characters. If the
|
| 269 |
last virtual member function called on `*this` (between `underflow`,
|
| 270 |
`overflow`, `seekoff`, and `seekpos`) was `overflow` then calls
|
| 271 |
`a_codecvt.unshift` (possibly several times) to determine a termination
|
| 272 |
sequence, inserts those characters and calls `overflow(traits::eof())`
|
| 273 |
again. Finally, regardless of whether any of the preceding calls fails
|
| 274 |
or throws an exception, the function closes the file (as if by calling
|
| 275 |
-
`
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
|
| 280 |
*Returns:* `this` on success, a null pointer otherwise.
|
| 281 |
|
| 282 |
-
`is_open() == false`.
|
| 283 |
|
| 284 |
#### Overridden virtual functions <a id="filebuf.virtuals">[[filebuf.virtuals]]</a>
|
| 285 |
|
| 286 |
``` cpp
|
| 287 |
-
streamsize showmanyc();
|
| 288 |
```
|
| 289 |
|
| 290 |
*Effects:* Behaves the same as
|
| 291 |
`basic_streambuf::showmanyc()` ([[streambuf.virtuals]]).
|
| 292 |
|
| 293 |
*Remarks:* An implementation might well provide an overriding definition
|
| 294 |
for this function signature if it can determine that more characters can
|
| 295 |
be read from the input sequence.
|
| 296 |
|
| 297 |
``` cpp
|
| 298 |
-
int_type underflow();
|
| 299 |
```
|
| 300 |
|
| 301 |
*Effects:* Behaves according to the description of
|
| 302 |
`basic_streambuf<charT, traits>::underflow()`, with the specialization
|
| 303 |
that a sequence of characters is read from the input sequence as if by
|
| 304 |
reading from the associated file into an internal buffer (`extern_buf`)
|
| 305 |
-
and then as if by doing
|
| 306 |
|
| 307 |
``` cpp
|
| 308 |
char extern_buf[XSIZE];
|
| 309 |
char* extern_end;
|
| 310 |
charT intern_buf[ISIZE];
|
|
@@ -318,20 +329,20 @@ This shall be done in such a way that the class can recover the position
|
|
| 318 |
(`fpos_t`) corresponding to each character between `intern_buf` and
|
| 319 |
`intern_end`. If the value of `r` indicates that `a_codecvt.in()` ran
|
| 320 |
out of space in `intern_buf`, retry with a larger `intern_buf`.
|
| 321 |
|
| 322 |
``` cpp
|
| 323 |
-
int_type uflow();
|
| 324 |
```
|
| 325 |
|
| 326 |
*Effects:* Behaves according to the description of
|
| 327 |
-
`basic_streambuf<charT,traits>::uflow()`, with the specialization that
|
| 328 |
-
sequence of characters is read from the input with the same method as
|
| 329 |
used by `underflow`.
|
| 330 |
|
| 331 |
``` cpp
|
| 332 |
-
int_type pbackfail(int_type c = traits::eof());
|
| 333 |
```
|
| 334 |
|
| 335 |
*Effects:* Puts back the character designated by `c` to the input
|
| 336 |
sequence, if possible, in one of three ways:
|
| 337 |
|
|
@@ -359,11 +370,11 @@ sequence.
|
|
| 359 |
If the function can succeed in more than one of these ways, it is
|
| 360 |
unspecified which way is chosen. The function can alter the number of
|
| 361 |
putback positions available as a result of any call.
|
| 362 |
|
| 363 |
``` cpp
|
| 364 |
-
int_type overflow(int_type c = traits::eof());
|
| 365 |
```
|
| 366 |
|
| 367 |
*Effects:* Behaves according to the description of
|
| 368 |
`basic_streambuf<charT, traits>::overflow(c)`, except that the behavior
|
| 369 |
of “consuming characters” is performed by first converting as if by:
|
|
@@ -392,31 +403,32 @@ and then
|
|
| 392 |
|
| 393 |
*Returns:* `traits::not_eof(c)` to indicate success, and `traits::eof()`
|
| 394 |
to indicate failure. If `is_open() == false`, the function always fails.
|
| 395 |
|
| 396 |
``` cpp
|
| 397 |
-
basic_streambuf* setbuf(char_type* s, streamsize n);
|
| 398 |
```
|
| 399 |
|
| 400 |
*Effects:* If `setbuf(0, 0)` is called on a stream before any I/O has
|
| 401 |
occurred on that stream, the stream becomes unbuffered. Otherwise the
|
| 402 |
results are *implementation-defined*. “Unbuffered” means that `pbase()`
|
| 403 |
and `pptr()` always return null and output to the file should appear as
|
| 404 |
soon as possible.
|
| 405 |
|
| 406 |
``` cpp
|
| 407 |
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 408 |
-
|
|
|
|
| 409 |
```
|
| 410 |
|
| 411 |
*Effects:* Let `width` denote `a_codecvt.encoding()`. If
|
| 412 |
`is_open() == false`, or `off != 0 && width <= 0`, then the positioning
|
| 413 |
operation fails. Otherwise, if `way != basic_ios::cur` or `off != 0`,
|
| 414 |
and if the last operation was output, then update the output sequence
|
| 415 |
and write any unshift sequence. Next, seek to the new position: if
|
| 416 |
-
`width > 0`, call `
|
| 417 |
-
|
| 418 |
|
| 419 |
*Remarks:* “The last operation was output” means either the last virtual
|
| 420 |
operation was overflow or the put buffer is non-empty. “Write any
|
| 421 |
unshift sequence” means, if `width` if less than zero then call
|
| 422 |
`a_codecvt.unshift(state, xbuf, xbuf+XSIZE, xbuf_end)` and output the
|
|
@@ -438,90 +450,99 @@ resultant stream position, if possible. If the positioning operation
|
|
| 438 |
fails, or if the object cannot represent the resultant stream position,
|
| 439 |
returns `pos_type(off_type(-1))`.
|
| 440 |
|
| 441 |
``` cpp
|
| 442 |
pos_type seekpos(pos_type sp,
|
| 443 |
-
|
|
|
|
| 444 |
```
|
| 445 |
|
| 446 |
Alters the file position, if possible, to correspond to the position
|
| 447 |
stored in `sp` (as described below). Altering the file position performs
|
| 448 |
as follows:
|
| 449 |
|
| 450 |
1. if `(om & ios_base::out) != 0`, then update the output sequence and
|
| 451 |
write any unshift sequence;
|
| 452 |
-
2. set the file position to `sp`;
|
| 453 |
3. if `(om & ios_base::in) != 0`, then update the input sequence;
|
| 454 |
|
| 455 |
where `om` is the open mode passed to the last call to `open()`. The
|
| 456 |
-
operation fails if `is_open()` returns false.
|
| 457 |
|
| 458 |
If `sp` is an invalid stream position, or if the function positions
|
| 459 |
neither sequence, the positioning operation fails. If `sp` has not been
|
| 460 |
obtained by a previous successful call to one of the positioning
|
| 461 |
functions (`seekoff` or `seekpos`) on the same file the effects are
|
| 462 |
undefined.
|
| 463 |
|
| 464 |
*Returns:* `sp` on success. Otherwise returns `pos_type(off_type(-1))`.
|
| 465 |
|
| 466 |
``` cpp
|
| 467 |
-
int sync();
|
| 468 |
```
|
| 469 |
|
| 470 |
*Effects:* If a put area exists, calls `filebuf::overflow` to write the
|
| 471 |
-
characters to the file
|
|
|
|
| 472 |
*implementation-defined*.
|
| 473 |
|
| 474 |
``` cpp
|
| 475 |
-
void imbue(const locale& loc);
|
| 476 |
```
|
| 477 |
|
| 478 |
-
If the file is not positioned at its beginning and the
|
| 479 |
-
current locale as determined by `a_codecvt.encoding()`
|
| 480 |
-
state-dependent ([[locale.codecvt.virtuals]]) then that facet is the
|
| 481 |
same as the corresponding facet of `loc`.
|
| 482 |
|
| 483 |
*Effects:* Causes characters inserted or extracted after this call to be
|
| 484 |
converted according to `loc` until another call of `imbue`.
|
| 485 |
|
| 486 |
-
This may require reconversion of previously converted
|
| 487 |
-
in turn may require the implementation to be able to
|
| 488 |
-
original contents of the file.
|
| 489 |
|
| 490 |
-
###
|
| 491 |
|
| 492 |
``` cpp
|
| 493 |
namespace std {
|
| 494 |
template <class charT, class traits = char_traits<charT>>
|
| 495 |
class basic_ifstream : public basic_istream<charT, traits> {
|
| 496 |
public:
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
|
| 503 |
-
// [ifstream.cons]
|
| 504 |
basic_ifstream();
|
| 505 |
explicit basic_ifstream(const char* s,
|
| 506 |
ios_base::openmode mode = ios_base::in);
|
|
|
|
|
|
|
| 507 |
explicit basic_ifstream(const string& s,
|
| 508 |
ios_base::openmode mode = ios_base::in);
|
|
|
|
|
|
|
| 509 |
basic_ifstream(const basic_ifstream& rhs) = delete;
|
| 510 |
basic_ifstream(basic_ifstream&& rhs);
|
| 511 |
|
| 512 |
-
// [ifstream.assign]
|
| 513 |
basic_ifstream& operator=(const basic_ifstream& rhs) = delete;
|
| 514 |
basic_ifstream& operator=(basic_ifstream&& rhs);
|
| 515 |
void swap(basic_ifstream& rhs);
|
| 516 |
|
| 517 |
-
// [ifstream.members]
|
| 518 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 519 |
|
| 520 |
bool is_open() const;
|
| 521 |
void open(const char* s, ios_base::openmode mode = ios_base::in);
|
|
|
|
|
|
|
| 522 |
void open(const string& s, ios_base::openmode mode = ios_base::in);
|
|
|
|
| 523 |
void close();
|
| 524 |
private:
|
| 525 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 526 |
};
|
| 527 |
|
|
@@ -542,18 +563,20 @@ presented here as:
|
|
| 542 |
|
| 543 |
``` cpp
|
| 544 |
basic_ifstream();
|
| 545 |
```
|
| 546 |
|
| 547 |
-
*Effects:* Constructs an object of class
|
| 548 |
-
initializing the base class with
|
| 549 |
-
`sb`
|
| 550 |
-
[[filebuf.cons]]).
|
| 551 |
|
| 552 |
``` cpp
|
| 553 |
explicit basic_ifstream(const char* s,
|
| 554 |
ios_base::openmode mode = ios_base::in);
|
|
|
|
|
|
|
| 555 |
```
|
| 556 |
|
| 557 |
*Effects:* Constructs an object of class `basic_ifstream`, initializing
|
| 558 |
the base class with `basic_istream(&sb)` and initializing `sb` with
|
| 559 |
`basic_filebuf<charT, traits>())` ([[istream.cons]], [[filebuf.cons]]),
|
|
@@ -561,13 +584,15 @@ then calls `rdbuf()->open(s, mode | ios_base::in)`. If that function
|
|
| 561 |
returns a null pointer, calls `setstate(failbit)`.
|
| 562 |
|
| 563 |
``` cpp
|
| 564 |
explicit basic_ifstream(const string& s,
|
| 565 |
ios_base::openmode mode = ios_base::in);
|
|
|
|
|
|
|
| 566 |
```
|
| 567 |
|
| 568 |
-
*Effects:*
|
| 569 |
|
| 570 |
``` cpp
|
| 571 |
basic_ifstream(basic_ifstream&& rhs);
|
| 572 |
```
|
| 573 |
|
|
@@ -598,11 +623,11 @@ void swap(basic_ifstream& rhs);
|
|
| 598 |
template <class charT, class traits>
|
| 599 |
void swap(basic_ifstream<charT, traits>& x,
|
| 600 |
basic_ifstream<charT, traits>& y);
|
| 601 |
```
|
| 602 |
|
| 603 |
-
*Effects:* `x.swap(y)`.
|
| 604 |
|
| 605 |
#### Member functions <a id="ifstream.members">[[ifstream.members]]</a>
|
| 606 |
|
| 607 |
``` cpp
|
| 608 |
basic_filebuf<charT, traits>* rdbuf() const;
|
|
@@ -616,64 +641,74 @@ bool is_open() const;
|
|
| 616 |
|
| 617 |
*Returns:* `rdbuf()->is_open()`.
|
| 618 |
|
| 619 |
``` cpp
|
| 620 |
void open(const char* s, ios_base::openmode mode = ios_base::in);
|
|
|
|
|
|
|
| 621 |
```
|
| 622 |
|
| 623 |
*Effects:* Calls `rdbuf()->open(s, mode | ios_base::in)`. If that
|
| 624 |
function does not return a null pointer calls `clear()`, otherwise calls
|
| 625 |
-
`setstate(failbit)` (which may throw `ios_base::failure`
|
| 626 |
-
([[iostate.flags]])
|
| 627 |
|
| 628 |
``` cpp
|
| 629 |
void open(const string& s, ios_base::openmode mode = ios_base::in);
|
|
|
|
| 630 |
```
|
| 631 |
|
| 632 |
-
*Effects:*
|
| 633 |
|
| 634 |
``` cpp
|
| 635 |
void close();
|
| 636 |
```
|
| 637 |
|
| 638 |
*Effects:* Calls `rdbuf()->close()` and, if that function returns a null
|
| 639 |
pointer, calls `setstate(failbit)` (which may throw
|
| 640 |
-
`ios_base::failure` ([[iostate.flags]])
|
| 641 |
|
| 642 |
-
###
|
| 643 |
|
| 644 |
``` cpp
|
| 645 |
namespace std {
|
| 646 |
template <class charT, class traits = char_traits<charT>>
|
| 647 |
class basic_ofstream : public basic_ostream<charT, traits> {
|
| 648 |
public:
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
|
| 655 |
-
// [ofstream.cons]
|
| 656 |
basic_ofstream();
|
| 657 |
explicit basic_ofstream(const char* s,
|
| 658 |
ios_base::openmode mode = ios_base::out);
|
|
|
|
|
|
|
| 659 |
explicit basic_ofstream(const string& s,
|
| 660 |
ios_base::openmode mode = ios_base::out);
|
|
|
|
|
|
|
| 661 |
basic_ofstream(const basic_ofstream& rhs) = delete;
|
| 662 |
basic_ofstream(basic_ofstream&& rhs);
|
| 663 |
|
| 664 |
-
// [ofstream.assign]
|
| 665 |
basic_ofstream& operator=(const basic_ofstream& rhs) = delete;
|
| 666 |
basic_ofstream& operator=(basic_ofstream&& rhs);
|
| 667 |
void swap(basic_ofstream& rhs);
|
| 668 |
|
| 669 |
-
// [ofstream.members]
|
| 670 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 671 |
|
| 672 |
bool is_open() const;
|
| 673 |
void open(const char* s, ios_base::openmode mode = ios_base::out);
|
|
|
|
|
|
|
| 674 |
void open(const string& s, ios_base::openmode mode = ios_base::out);
|
|
|
|
| 675 |
void close();
|
| 676 |
private:
|
| 677 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 678 |
};
|
| 679 |
|
|
@@ -694,32 +729,37 @@ presented here as:
|
|
| 694 |
|
| 695 |
``` cpp
|
| 696 |
basic_ofstream();
|
| 697 |
```
|
| 698 |
|
| 699 |
-
*Effects:* Constructs an object of class
|
| 700 |
-
initializing the base class with
|
| 701 |
-
`sb`
|
| 702 |
-
[[filebuf.cons]]).
|
| 703 |
|
| 704 |
``` cpp
|
| 705 |
explicit basic_ofstream(const char* s,
|
| 706 |
ios_base::openmode mode = ios_base::out);
|
|
|
|
|
|
|
| 707 |
```
|
| 708 |
|
| 709 |
-
*Effects:* Constructs an object of class
|
| 710 |
-
initializing the base class with
|
| 711 |
-
`sb`
|
| 712 |
-
[[
|
| 713 |
-
|
|
|
|
| 714 |
|
| 715 |
``` cpp
|
| 716 |
explicit basic_ofstream(const string& s,
|
| 717 |
ios_base::openmode mode = ios_base::out);
|
|
|
|
|
|
|
| 718 |
```
|
| 719 |
|
| 720 |
-
*Effects:*
|
| 721 |
|
| 722 |
``` cpp
|
| 723 |
basic_ofstream(basic_ofstream&& rhs);
|
| 724 |
```
|
| 725 |
|
|
@@ -750,11 +790,11 @@ void swap(basic_ofstream& rhs);
|
|
| 750 |
template <class charT, class traits>
|
| 751 |
void swap(basic_ofstream<charT, traits>& x,
|
| 752 |
basic_ofstream<charT, traits>& y);
|
| 753 |
```
|
| 754 |
|
| 755 |
-
*Effects:* `x.swap(y)`.
|
| 756 |
|
| 757 |
#### Member functions <a id="ofstream.members">[[ofstream.members]]</a>
|
| 758 |
|
| 759 |
``` cpp
|
| 760 |
basic_filebuf<charT, traits>* rdbuf() const;
|
|
@@ -768,66 +808,83 @@ bool is_open() const;
|
|
| 768 |
|
| 769 |
*Returns:* `rdbuf()->is_open()`.
|
| 770 |
|
| 771 |
``` cpp
|
| 772 |
void open(const char* s, ios_base::openmode mode = ios_base::out);
|
|
|
|
|
|
|
| 773 |
```
|
| 774 |
|
| 775 |
*Effects:* Calls `rdbuf()->open(s, mode | ios_base::out)`. If that
|
| 776 |
function does not return a null pointer calls `clear()`, otherwise calls
|
| 777 |
-
`setstate(failbit)` (which may throw `ios_base::failure`
|
| 778 |
-
([[iostate.flags]])
|
| 779 |
|
| 780 |
``` cpp
|
| 781 |
void close();
|
| 782 |
```
|
| 783 |
|
| 784 |
*Effects:* Calls `rdbuf()->close()` and, if that function fails (returns
|
| 785 |
a null pointer), calls `setstate(failbit)` (which may throw
|
| 786 |
-
`ios_base::failure` ([[iostate.flags]])
|
| 787 |
|
| 788 |
``` cpp
|
| 789 |
void open(const string& s, ios_base::openmode mode = ios_base::out);
|
|
|
|
| 790 |
```
|
| 791 |
|
| 792 |
-
*Effects:*
|
| 793 |
|
| 794 |
-
###
|
| 795 |
|
| 796 |
``` cpp
|
| 797 |
namespace std {
|
| 798 |
template <class charT, class traits = char_traits<charT>>
|
| 799 |
-
class basic_fstream
|
| 800 |
-
: public basic_iostream<charT,traits> {
|
| 801 |
-
|
| 802 |
public:
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
|
| 809 |
-
// constructors
|
| 810 |
basic_fstream();
|
| 811 |
-
explicit basic_fstream(
|
|
|
|
| 812 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 813 |
-
explicit basic_fstream(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 814 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 815 |
basic_fstream(const basic_fstream& rhs) = delete;
|
| 816 |
basic_fstream(basic_fstream&& rhs);
|
| 817 |
|
| 818 |
-
// [fstream.assign]
|
| 819 |
basic_fstream& operator=(const basic_fstream& rhs) = delete;
|
| 820 |
basic_fstream& operator=(basic_fstream&& rhs);
|
| 821 |
void swap(basic_fstream& rhs);
|
| 822 |
|
| 823 |
-
//
|
| 824 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 825 |
bool is_open() const;
|
| 826 |
-
void open(
|
|
|
|
| 827 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 828 |
-
void open(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 829 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 830 |
void close();
|
| 831 |
|
| 832 |
private:
|
| 833 |
basic_filebuf<charT, traits> sb; // exposition only
|
|
@@ -838,13 +895,13 @@ namespace std {
|
|
| 838 |
basic_fstream<charT, traits>& y);
|
| 839 |
}
|
| 840 |
```
|
| 841 |
|
| 842 |
The class template `basic_fstream<charT, traits>` supports reading and
|
| 843 |
-
writing from named files. It uses a `basic_filebuf<charT,traits>`
|
| 844 |
-
to control the associated sequences. For the sake of exposition,
|
| 845 |
-
maintained data is presented here as:
|
| 846 |
|
| 847 |
- `sb`, the `basic_filebuf` object.
|
| 848 |
|
| 849 |
#### `basic_fstream` constructors <a id="fstream.cons">[[fstream.cons]]</a>
|
| 850 |
|
|
@@ -855,26 +912,34 @@ basic_fstream();
|
|
| 855 |
*Effects:* Constructs an object of class `basic_fstream<charT, traits>`,
|
| 856 |
initializing the base class with `basic_iostream(&sb)` and initializing
|
| 857 |
`sb` with `basic_filebuf<charT, traits>()`.
|
| 858 |
|
| 859 |
``` cpp
|
| 860 |
-
explicit basic_fstream(
|
|
|
|
| 861 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
|
|
|
|
|
|
|
|
|
| 862 |
```
|
| 863 |
|
| 864 |
*Effects:* Constructs an object of class `basic_fstream<charT, traits>`,
|
| 865 |
initializing the base class with `basic_iostream(&sb)` and initializing
|
| 866 |
`sb` with `basic_filebuf<charT, traits>()`. Then calls
|
| 867 |
`rdbuf()->open(s, mode)`. If that function returns a null pointer, calls
|
| 868 |
`setstate(failbit)`.
|
| 869 |
|
| 870 |
``` cpp
|
| 871 |
-
explicit basic_fstream(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 872 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 873 |
```
|
| 874 |
|
| 875 |
-
*Effects:*
|
| 876 |
|
| 877 |
``` cpp
|
| 878 |
basic_fstream(basic_fstream&& rhs);
|
| 879 |
```
|
| 880 |
|
|
@@ -905,11 +970,11 @@ void swap(basic_fstream& rhs);
|
|
| 905 |
template <class charT, class traits>
|
| 906 |
void swap(basic_fstream<charT, traits>& x,
|
| 907 |
basic_fstream<charT, traits>& y);
|
| 908 |
```
|
| 909 |
|
| 910 |
-
*Effects:* `x.swap(y)`.
|
| 911 |
|
| 912 |
#### Member functions <a id="fstream.members">[[fstream.members]]</a>
|
| 913 |
|
| 914 |
``` cpp
|
| 915 |
basic_filebuf<charT, traits>* rdbuf() const;
|
|
@@ -922,365 +987,37 @@ bool is_open() const;
|
|
| 922 |
```
|
| 923 |
|
| 924 |
*Returns:* `rdbuf()->is_open()`.
|
| 925 |
|
| 926 |
``` cpp
|
| 927 |
-
void open(
|
|
|
|
| 928 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
|
|
|
|
|
|
|
|
|
| 929 |
```
|
| 930 |
|
| 931 |
*Effects:* Calls `rdbuf()->open(s, mode)`. If that function does not
|
| 932 |
return a null pointer calls `clear()`, otherwise calls
|
| 933 |
-
`setstate(failbit)`
|
| 934 |
`ios_base::failure`) ([[iostate.flags]]).
|
| 935 |
|
| 936 |
``` cpp
|
| 937 |
-
void open(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 938 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 939 |
```
|
| 940 |
|
| 941 |
-
*Effects:*
|
| 942 |
|
| 943 |
``` cpp
|
| 944 |
void close();
|
| 945 |
```
|
| 946 |
|
| 947 |
-
*Effects:* Calls `rdbuf()->close()` and, if that function returns
|
| 948 |
-
|
| 949 |
-
|
| 950 |
|
| 951 |
-
### C library files <a id="c.files">[[c.files]]</a>
|
| 952 |
-
|
| 953 |
-
Table [[tab:iostreams.hdr.cstdio]] describes header `<cstdio>`. C++does
|
| 954 |
-
not define the function `gets`.
|
| 955 |
-
|
| 956 |
-
Calls to the function `tmpnam` with an argument of `NULL` may introduce
|
| 957 |
-
a data race ([[res.on.data.races]]) with other calls to `tmpnam` with
|
| 958 |
-
an argument of `NULL`.
|
| 959 |
-
|
| 960 |
-
ISO C 7.9, Amendment 1 4.6.2.
|
| 961 |
-
|
| 962 |
-
Table [[tab:iostreams.hdr.cinttypes]] describes header `<cinttypes>`.
|
| 963 |
-
The macros defined by `<cinttypes>` are provided unconditionally. In
|
| 964 |
-
particular, the symbol `__STDC_FORMAT_MACROS`, mentioned in footnote 182
|
| 965 |
-
of the C standard, plays no role in C++.
|
| 966 |
-
|
| 967 |
-
The contents of header `<cinttypes>` are the same as the Standard C
|
| 968 |
-
Library header `<inttypes.h>`, with the following changes:
|
| 969 |
-
|
| 970 |
-
- the header `<cinttypes>` includes the header `<cstdint>` instead of
|
| 971 |
-
`<stdint.h>`, and
|
| 972 |
-
- if and only if the type `intmax_t` designates an extended integer
|
| 973 |
-
type ([[basic.fundamental]]), the following function signatures are
|
| 974 |
-
added:
|
| 975 |
-
``` cpp
|
| 976 |
-
intmax_t abs(intmax_t);
|
| 977 |
-
imaxdiv_t div(intmax_t, intmax_t);
|
| 978 |
-
```
|
| 979 |
-
|
| 980 |
-
which shall have the same semantics as the function signatures
|
| 981 |
-
`intmax_t imaxabs(intmax_t)` and
|
| 982 |
-
`imaxdiv_t imaxdiv(intmax_t, intmax_t)`, respectively.
|
| 983 |
-
|
| 984 |
-
<!-- Link reference definitions -->
|
| 985 |
-
[adjustfield.manip]: #adjustfield.manip
|
| 986 |
-
[basefield.manip]: #basefield.manip
|
| 987 |
-
[basic.fundamental]: basic.md#basic.fundamental
|
| 988 |
-
[basic.ios.cons]: #basic.ios.cons
|
| 989 |
-
[basic.ios.members]: #basic.ios.members
|
| 990 |
-
[bitmask.types]: library.md#bitmask.types
|
| 991 |
-
[c.files]: #c.files
|
| 992 |
-
[enumerated.types]: library.md#enumerated.types
|
| 993 |
-
[error.reporting]: #error.reporting
|
| 994 |
-
[ext.manip]: #ext.manip
|
| 995 |
-
[fig:streampos]: #fig:streampos
|
| 996 |
-
[file.streams]: #file.streams
|
| 997 |
-
[filebuf]: #filebuf
|
| 998 |
-
[filebuf.assign]: #filebuf.assign
|
| 999 |
-
[filebuf.cons]: #filebuf.cons
|
| 1000 |
-
[filebuf.members]: #filebuf.members
|
| 1001 |
-
[filebuf.virtuals]: #filebuf.virtuals
|
| 1002 |
-
[floatfield.manip]: #floatfield.manip
|
| 1003 |
-
[fmtflags.manip]: #fmtflags.manip
|
| 1004 |
-
[fmtflags.state]: #fmtflags.state
|
| 1005 |
-
[fpos]: #fpos
|
| 1006 |
-
[fpos.members]: #fpos.members
|
| 1007 |
-
[fpos.operations]: #fpos.operations
|
| 1008 |
-
[fstream]: #fstream
|
| 1009 |
-
[fstream.assign]: #fstream.assign
|
| 1010 |
-
[fstream.cons]: #fstream.cons
|
| 1011 |
-
[fstream.members]: #fstream.members
|
| 1012 |
-
[fstreams]: #fstreams
|
| 1013 |
-
[ifstream]: #ifstream
|
| 1014 |
-
[ifstream.assign]: #ifstream.assign
|
| 1015 |
-
[ifstream.cons]: #ifstream.cons
|
| 1016 |
-
[ifstream.members]: #ifstream.members
|
| 1017 |
-
[input.output]: #input.output
|
| 1018 |
-
[input.output.general]: #input.output.general
|
| 1019 |
-
[input.streams]: #input.streams
|
| 1020 |
-
[intro.multithread]: intro.md#intro.multithread
|
| 1021 |
-
[ios]: #ios
|
| 1022 |
-
[ios.base]: #ios.base
|
| 1023 |
-
[ios.base.callback]: #ios.base.callback
|
| 1024 |
-
[ios.base.cons]: #ios.base.cons
|
| 1025 |
-
[ios.base.locales]: #ios.base.locales
|
| 1026 |
-
[ios.base.storage]: #ios.base.storage
|
| 1027 |
-
[ios.members.static]: #ios.members.static
|
| 1028 |
-
[ios.overview]: #ios.overview
|
| 1029 |
-
[ios.types]: #ios.types
|
| 1030 |
-
[ios::Init]: #ios::Init
|
| 1031 |
-
[ios::failure]: #ios::failure
|
| 1032 |
-
[ios::fmtflags]: #ios::fmtflags
|
| 1033 |
-
[ios::iostate]: #ios::iostate
|
| 1034 |
-
[ios::openmode]: #ios::openmode
|
| 1035 |
-
[ios::seekdir]: #ios::seekdir
|
| 1036 |
-
[iostate.flags]: #iostate.flags
|
| 1037 |
-
[iostream.assign]: #iostream.assign
|
| 1038 |
-
[iostream.cons]: #iostream.cons
|
| 1039 |
-
[iostream.dest]: #iostream.dest
|
| 1040 |
-
[iostream.format]: #iostream.format
|
| 1041 |
-
[iostream.format.overview]: #iostream.format.overview
|
| 1042 |
-
[iostream.forward]: #iostream.forward
|
| 1043 |
-
[iostream.limits.imbue]: #iostream.limits.imbue
|
| 1044 |
-
[iostream.objects]: #iostream.objects
|
| 1045 |
-
[iostream.objects.overview]: #iostream.objects.overview
|
| 1046 |
-
[iostreamclass]: #iostreamclass
|
| 1047 |
-
[iostreams.base]: #iostreams.base
|
| 1048 |
-
[iostreams.base.overview]: #iostreams.base.overview
|
| 1049 |
-
[iostreams.limits.pos]: #iostreams.limits.pos
|
| 1050 |
-
[iostreams.requirements]: #iostreams.requirements
|
| 1051 |
-
[iostreams.threadsafety]: #iostreams.threadsafety
|
| 1052 |
-
[istream]: #istream
|
| 1053 |
-
[istream.assign]: #istream.assign
|
| 1054 |
-
[istream.cons]: #istream.cons
|
| 1055 |
-
[istream.formatted]: #istream.formatted
|
| 1056 |
-
[istream.formatted.arithmetic]: #istream.formatted.arithmetic
|
| 1057 |
-
[istream.formatted.reqmts]: #istream.formatted.reqmts
|
| 1058 |
-
[istream.manip]: #istream.manip
|
| 1059 |
-
[istream.rvalue]: #istream.rvalue
|
| 1060 |
-
[istream.unformatted]: #istream.unformatted
|
| 1061 |
-
[istream::extractors]: #istream::extractors
|
| 1062 |
-
[istream::sentry]: #istream::sentry
|
| 1063 |
-
[istringstream]: #istringstream
|
| 1064 |
-
[istringstream.assign]: #istringstream.assign
|
| 1065 |
-
[istringstream.cons]: #istringstream.cons
|
| 1066 |
-
[istringstream.members]: #istringstream.members
|
| 1067 |
-
[limits]: language.md#limits
|
| 1068 |
-
[locale.codecvt.virtuals]: localization.md#locale.codecvt.virtuals
|
| 1069 |
-
[locale.num.get]: localization.md#locale.num.get
|
| 1070 |
-
[narrow.stream.objects]: #narrow.stream.objects
|
| 1071 |
-
[ofstream]: #ofstream
|
| 1072 |
-
[ofstream.assign]: #ofstream.assign
|
| 1073 |
-
[ofstream.cons]: #ofstream.cons
|
| 1074 |
-
[ofstream.members]: #ofstream.members
|
| 1075 |
-
[ostream]: #ostream
|
| 1076 |
-
[ostream.assign]: #ostream.assign
|
| 1077 |
-
[ostream.cons]: #ostream.cons
|
| 1078 |
-
[ostream.formatted]: #ostream.formatted
|
| 1079 |
-
[ostream.formatted.reqmts]: #ostream.formatted.reqmts
|
| 1080 |
-
[ostream.inserters]: #ostream.inserters
|
| 1081 |
-
[ostream.inserters.arithmetic]: #ostream.inserters.arithmetic
|
| 1082 |
-
[ostream.inserters.character]: #ostream.inserters.character
|
| 1083 |
-
[ostream.manip]: #ostream.manip
|
| 1084 |
-
[ostream.rvalue]: #ostream.rvalue
|
| 1085 |
-
[ostream.seeks]: #ostream.seeks
|
| 1086 |
-
[ostream.unformatted]: #ostream.unformatted
|
| 1087 |
-
[ostream::sentry]: #ostream::sentry
|
| 1088 |
-
[ostringstream]: #ostringstream
|
| 1089 |
-
[ostringstream.assign]: #ostringstream.assign
|
| 1090 |
-
[ostringstream.cons]: #ostringstream.cons
|
| 1091 |
-
[ostringstream.members]: #ostringstream.members
|
| 1092 |
-
[output.streams]: #output.streams
|
| 1093 |
-
[quoted.manip]: #quoted.manip
|
| 1094 |
-
[res.on.data.races]: library.md#res.on.data.races
|
| 1095 |
-
[res.on.exception.handling]: library.md#res.on.exception.handling
|
| 1096 |
-
[std.ios.manip]: #std.ios.manip
|
| 1097 |
-
[std.manip]: #std.manip
|
| 1098 |
-
[stream.buffers]: #stream.buffers
|
| 1099 |
-
[stream.buffers.overview]: #stream.buffers.overview
|
| 1100 |
-
[stream.types]: #stream.types
|
| 1101 |
-
[streambuf]: #streambuf
|
| 1102 |
-
[streambuf.assign]: #streambuf.assign
|
| 1103 |
-
[streambuf.buffer]: #streambuf.buffer
|
| 1104 |
-
[streambuf.cons]: #streambuf.cons
|
| 1105 |
-
[streambuf.get.area]: #streambuf.get.area
|
| 1106 |
-
[streambuf.locales]: #streambuf.locales
|
| 1107 |
-
[streambuf.members]: #streambuf.members
|
| 1108 |
-
[streambuf.protected]: #streambuf.protected
|
| 1109 |
-
[streambuf.pub.get]: #streambuf.pub.get
|
| 1110 |
-
[streambuf.pub.pback]: #streambuf.pub.pback
|
| 1111 |
-
[streambuf.pub.put]: #streambuf.pub.put
|
| 1112 |
-
[streambuf.put.area]: #streambuf.put.area
|
| 1113 |
-
[streambuf.reqts]: #streambuf.reqts
|
| 1114 |
-
[streambuf.virt.buffer]: #streambuf.virt.buffer
|
| 1115 |
-
[streambuf.virt.get]: #streambuf.virt.get
|
| 1116 |
-
[streambuf.virt.locales]: #streambuf.virt.locales
|
| 1117 |
-
[streambuf.virt.pback]: #streambuf.virt.pback
|
| 1118 |
-
[streambuf.virt.put]: #streambuf.virt.put
|
| 1119 |
-
[streambuf.virtuals]: #streambuf.virtuals
|
| 1120 |
-
[string.classes]: strings.md#string.classes
|
| 1121 |
-
[string.streams]: #string.streams
|
| 1122 |
-
[string.streams.overview]: #string.streams.overview
|
| 1123 |
-
[stringbuf]: #stringbuf
|
| 1124 |
-
[stringbuf.assign]: #stringbuf.assign
|
| 1125 |
-
[stringbuf.cons]: #stringbuf.cons
|
| 1126 |
-
[stringbuf.members]: #stringbuf.members
|
| 1127 |
-
[stringbuf.virtuals]: #stringbuf.virtuals
|
| 1128 |
-
[strings]: strings.md#strings
|
| 1129 |
-
[stringstream]: #stringstream
|
| 1130 |
-
[stringstream.assign]: #stringstream.assign
|
| 1131 |
-
[stringstream.cons]: #stringstream.cons
|
| 1132 |
-
[stringstream.members]: #stringstream.members
|
| 1133 |
-
[tab:iostreams.basicios.init.effects]: #tab:iostreams.basicios.init.effects
|
| 1134 |
-
[tab:iostreams.copyfmt.effects]: #tab:iostreams.copyfmt.effects
|
| 1135 |
-
[tab:iostreams.file.open.modes]: #tab:iostreams.file.open.modes
|
| 1136 |
-
[tab:iostreams.fmtflags.constants]: #tab:iostreams.fmtflags.constants
|
| 1137 |
-
[tab:iostreams.fmtflags.effects]: #tab:iostreams.fmtflags.effects
|
| 1138 |
-
[tab:iostreams.hdr.cinttypes]: #tab:iostreams.hdr.cinttypes
|
| 1139 |
-
[tab:iostreams.hdr.cstdio]: #tab:iostreams.hdr.cstdio
|
| 1140 |
-
[tab:iostreams.iostate.effects]: #tab:iostreams.iostate.effects
|
| 1141 |
-
[tab:iostreams.lib.summary]: #tab:iostreams.lib.summary
|
| 1142 |
-
[tab:iostreams.newoff.values]: #tab:iostreams.newoff.values
|
| 1143 |
-
[tab:iostreams.openmode.effects]: #tab:iostreams.openmode.effects
|
| 1144 |
-
[tab:iostreams.position.requirements]: #tab:iostreams.position.requirements
|
| 1145 |
-
[tab:iostreams.seekdir.effects]: #tab:iostreams.seekdir.effects
|
| 1146 |
-
[tab:iostreams.seekoff.effects]: #tab:iostreams.seekoff.effects
|
| 1147 |
-
[tab:iostreams.seekoff.positioning]: #tab:iostreams.seekoff.positioning
|
| 1148 |
-
[wide.stream.objects]: #wide.stream.objects
|
| 1149 |
-
|
| 1150 |
-
[^1]: It is the implementation’s responsibility to implement headers so
|
| 1151 |
-
that including `<iosfwd>` and other headers does not violate the
|
| 1152 |
-
rules about multiple occurrences of default arguments.
|
| 1153 |
-
|
| 1154 |
-
[^2]: If it is possible for them to do so, implementations are
|
| 1155 |
-
encouraged to initialize the objects earlier than required.
|
| 1156 |
-
|
| 1157 |
-
[^3]: Constructors and destructors for static objects can access these
|
| 1158 |
-
objects to read input from `stdin` or write output to `stdout` or
|
| 1159 |
-
`stderr`.
|
| 1160 |
-
|
| 1161 |
-
[^4]: Typically `long long`.
|
| 1162 |
-
|
| 1163 |
-
[^5]: `streamsize` is used in most places where ISO C would use
|
| 1164 |
-
`size_t`. Most of the uses of `streamsize` could use `size_t`,
|
| 1165 |
-
except for the `strstreambuf` constructors, which require negative
|
| 1166 |
-
values. It should probably be the signed type corresponding to
|
| 1167 |
-
`size_t` (which is what Posix.2 calls `ssize_t`).
|
| 1168 |
-
|
| 1169 |
-
[^6]: This implies that operations on a standard iostream object can be
|
| 1170 |
-
mixed arbitrarily with operations on the corresponding stdio stream.
|
| 1171 |
-
In practical terms, synchronization usually means that a standard
|
| 1172 |
-
iostream object and a standard stdio object share a buffer.
|
| 1173 |
-
|
| 1174 |
-
[^7]: An implementation is free to implement both the integer array
|
| 1175 |
-
pointed at by `iarray` and the pointer array pointed at by `parray`
|
| 1176 |
-
as sparse data structures, possibly with a one-element cache for
|
| 1177 |
-
each.
|
| 1178 |
-
|
| 1179 |
-
[^8]: for example, because it cannot allocate space.
|
| 1180 |
-
|
| 1181 |
-
[^9]: for example, because it cannot allocate space.
|
| 1182 |
-
|
| 1183 |
-
[^10]: This suggests an infinite amount of copying, but the
|
| 1184 |
-
implementation can keep track of the maximum element of the arrays
|
| 1185 |
-
that is non-zero.
|
| 1186 |
-
|
| 1187 |
-
[^11]: Checking `badbit` also for `fail()` is historical practice.
|
| 1188 |
-
|
| 1189 |
-
[^12]: The function signature `dec(ios_base&)` can be called by the
|
| 1190 |
-
function signature
|
| 1191 |
-
`basic_ostream& stream::operator<<(ios_base& (*)(ios_base&))` to
|
| 1192 |
-
permit expressions of the form `cout <<dec` to change the format
|
| 1193 |
-
flags stored in `cout`.
|
| 1194 |
-
|
| 1195 |
-
[^13]: The default constructor is protected for class `basic_streambuf`
|
| 1196 |
-
to assure that only objects for classes derived from this class may
|
| 1197 |
-
be constructed.
|
| 1198 |
-
|
| 1199 |
-
[^14]: `underflow` or `uflow` might fail by throwing an exception
|
| 1200 |
-
prematurely. The intention is not only that the calls will not
|
| 1201 |
-
return `eof()` but that they will return “immediately.”
|
| 1202 |
-
|
| 1203 |
-
[^15]: Classes derived from `basic_streambuf` can provide more efficient
|
| 1204 |
-
ways to implement `xsgetn()` and `xsputn()` by overriding these
|
| 1205 |
-
definitions from the base class.
|
| 1206 |
-
|
| 1207 |
-
[^16]: Typically, `overflow` returns `c` to indicate success, except
|
| 1208 |
-
when `traits::eq_int_type(c,traits::eof())` returns `true`, in which
|
| 1209 |
-
case it returns `traits::not_eof(c)`.
|
| 1210 |
-
|
| 1211 |
-
[^17]: This will be possible only in functions that are part of the
|
| 1212 |
-
library. The semantics of the constructor used in user code is as
|
| 1213 |
-
specified.
|
| 1214 |
-
|
| 1215 |
-
[^18]: The sentry constructor and destructor can also perform additional
|
| 1216 |
-
implementation-dependent operations.
|
| 1217 |
-
|
| 1218 |
-
[^19]: This is done without causing an `ios::failure` to be thrown.
|
| 1219 |
-
|
| 1220 |
-
[^20]: See, for example, the function signature
|
| 1221 |
-
`ws(basic_istream&)` ([[istream.manip]]).
|
| 1222 |
-
|
| 1223 |
-
[^21]: See, for example, the function signature
|
| 1224 |
-
`dec(ios_base&)` ([[basefield.manip]]).
|
| 1225 |
-
|
| 1226 |
-
[^22]: This is done without causing an `ios::failure` to be thrown.
|
| 1227 |
-
|
| 1228 |
-
[^23]: Note that this function is not overloaded on types `signed char`
|
| 1229 |
-
and `unsigned char`.
|
| 1230 |
-
|
| 1231 |
-
[^24]: Note that this function is not overloaded on types `signed char`
|
| 1232 |
-
and `unsigned char`.
|
| 1233 |
-
|
| 1234 |
-
[^25]: Note that this function is not overloaded on types `signed char`
|
| 1235 |
-
and `unsigned char`.
|
| 1236 |
-
|
| 1237 |
-
[^26]: Since the final input character is “extracted,” it is counted in
|
| 1238 |
-
the `gcount()`, even though it is not stored.
|
| 1239 |
-
|
| 1240 |
-
[^27]: This allows an input line which exactly fills the buffer, without
|
| 1241 |
-
setting `failbit`. This is different behavior than the historical
|
| 1242 |
-
AT&T implementation.
|
| 1243 |
-
|
| 1244 |
-
[^28]: This implies an empty input line will not cause `failbit` to be
|
| 1245 |
-
set.
|
| 1246 |
-
|
| 1247 |
-
[^29]: Note that this function is not overloaded on types `signed char`
|
| 1248 |
-
and `unsigned char`.
|
| 1249 |
-
|
| 1250 |
-
[^30]: The call `os.tie()->flush()` does not necessarily occur if the
|
| 1251 |
-
function can determine that no synchronization is necessary.
|
| 1252 |
-
|
| 1253 |
-
[^31]: The `sentry` constructor and destructor can also perform
|
| 1254 |
-
additional implementation-dependent operations.
|
| 1255 |
-
|
| 1256 |
-
[^32]: without causing an `ios::failure` to be thrown.
|
| 1257 |
-
|
| 1258 |
-
[^33]: See, for example, the function signature
|
| 1259 |
-
`endl(basic_ostream&)` ([[ostream.manip]]).
|
| 1260 |
-
|
| 1261 |
-
[^34]: See, for example, the function signature
|
| 1262 |
-
`dec(ios_base&)` ([[basefield.manip]]).
|
| 1263 |
-
|
| 1264 |
-
[^35]: without causing an `ios::failure` to be thrown.
|
| 1265 |
-
|
| 1266 |
-
[^36]: Note that this function is not overloaded on types `signed char`
|
| 1267 |
-
and `unsigned char`.
|
| 1268 |
-
|
| 1269 |
-
[^37]: Note that this function is not overloaded on types `signed char`
|
| 1270 |
-
and `unsigned char`.
|
| 1271 |
-
|
| 1272 |
-
[^38]: The expression `cin >>resetiosflags(ios_base::skipws)` clears
|
| 1273 |
-
`ios_base::skipws` in the format flags stored in the
|
| 1274 |
-
`basic_istream<charT,traits>` object `cin` (the same as
|
| 1275 |
-
`cin >>noskipws`), and the expression
|
| 1276 |
-
`cout << resetiosflags(ios_base::showbase)` clears
|
| 1277 |
-
`ios_base::showbase` in the format flags stored in the
|
| 1278 |
-
`basic_ostream<charT,traits>` object `cout` (the same as
|
| 1279 |
-
`cout <<noshowbase`).
|
| 1280 |
-
|
| 1281 |
-
[^39]: The macro `SEEK_END` is defined, and the function signatures
|
| 1282 |
-
`fopen(const char*, const char*)` and `fseek(FILE*, long, int)` are
|
| 1283 |
-
declared, in `<cstdio>` ([[c.files]]).
|
| 1284 |
-
|
| 1285 |
-
[^40]: The function signature `fclose(FILE*)` is declared in `<cstdio>`
|
| 1286 |
-
([[c.files]]).
|
|
|
|
| 1 |
## File-based streams <a id="file.streams">[[file.streams]]</a>
|
| 2 |
|
| 3 |
+
### Header `<fstream>` synopsis <a id="fstream.syn">[[fstream.syn]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
namespace std {
|
| 7 |
template <class charT, class traits = char_traits<charT>>
|
| 8 |
class basic_filebuf;
|
| 9 |
+
using filebuf = basic_filebuf<char>;
|
| 10 |
+
using wfilebuf = basic_filebuf<wchar_t>;
|
| 11 |
|
| 12 |
template <class charT, class traits = char_traits<charT>>
|
| 13 |
class basic_ifstream;
|
| 14 |
+
using ifstream = basic_ifstream<char>;
|
| 15 |
+
using wifstream = basic_ifstream<wchar_t>;
|
| 16 |
|
| 17 |
template <class charT, class traits = char_traits<charT>>
|
| 18 |
class basic_ofstream;
|
| 19 |
+
using ofstream = basic_ofstream<char>;
|
| 20 |
+
using wofstream = basic_ofstream<wchar_t>;
|
| 21 |
|
| 22 |
template <class charT, class traits = char_traits<charT>>
|
| 23 |
class basic_fstream;
|
| 24 |
+
using fstream = basic_fstream<char>;
|
| 25 |
+
using wfstream = basic_fstream<wchar_t>;
|
| 26 |
}
|
| 27 |
```
|
| 28 |
|
| 29 |
+
The header `<fstream>` defines four class templates and eight types that
|
| 30 |
+
associate stream buffers with files and assist reading and writing
|
| 31 |
+
files.
|
| 32 |
|
| 33 |
+
[*Note 1*: The class template `basic_filebuf` treats a file as a source
|
| 34 |
+
or sink of bytes. In an environment that uses a large character set, the
|
| 35 |
+
file typically holds multibyte character sequences and the
|
| 36 |
+
`basic_filebuf` object converts those multibyte sequences into wide
|
| 37 |
+
character sequences. — *end note*]
|
| 38 |
|
| 39 |
+
In this subclause, member functions taking arguments of
|
| 40 |
+
`const filesystem::path::value_type*` are only be provided on systems
|
| 41 |
+
where `filesystem::path::value_type` ([[fs.class.path]]) is not `char`.
|
| 42 |
+
|
| 43 |
+
[*Note 2*: These functions enable class `path` support for systems with
|
| 44 |
+
a wide native path character type, such as `wchar_t`. — *end note*]
|
| 45 |
+
|
| 46 |
+
### Class template `basic_filebuf` <a id="filebuf">[[filebuf]]</a>
|
| 47 |
|
| 48 |
``` cpp
|
| 49 |
namespace std {
|
| 50 |
template <class charT, class traits = char_traits<charT>>
|
| 51 |
class basic_filebuf : public basic_streambuf<charT, traits> {
|
| 52 |
public:
|
| 53 |
+
using char_type = charT;
|
| 54 |
+
using int_type = typename traits::int_type;
|
| 55 |
+
using pos_type = typename traits::pos_type;
|
| 56 |
+
using off_type = typename traits::off_type;
|
| 57 |
+
using traits_type = traits;
|
| 58 |
|
| 59 |
+
// [filebuf.cons], constructors/destructor
|
| 60 |
basic_filebuf();
|
| 61 |
basic_filebuf(const basic_filebuf& rhs) = delete;
|
| 62 |
basic_filebuf(basic_filebuf&& rhs);
|
| 63 |
virtual ~basic_filebuf();
|
| 64 |
|
| 65 |
+
// [filebuf.assign], assign and swap
|
| 66 |
basic_filebuf& operator=(const basic_filebuf& rhs) = delete;
|
| 67 |
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 68 |
void swap(basic_filebuf& rhs);
|
| 69 |
|
| 70 |
+
// [filebuf.members], members
|
| 71 |
bool is_open() const;
|
| 72 |
+
basic_filebuf* open(const char* s, ios_base::openmode mode);
|
| 73 |
+
basic_filebuf* open(const filesystem::path::value_type* s,
|
| 74 |
+
ios_base::openmode mode); // wide systems only; see [fstream.syn]
|
| 75 |
+
basic_filebuf* open(const string& s,
|
| 76 |
ios_base::openmode mode);
|
| 77 |
+
basic_filebuf* open(const filesystem::path& s,
|
| 78 |
ios_base::openmode mode);
|
| 79 |
+
basic_filebuf* close();
|
| 80 |
|
| 81 |
protected:
|
| 82 |
+
// [filebuf.virtuals], overridden virtual functions
|
| 83 |
+
streamsize showmanyc() override;
|
| 84 |
+
int_type underflow() override;
|
| 85 |
+
int_type uflow() override;
|
| 86 |
+
int_type pbackfail(int_type c = traits::eof()) override;
|
| 87 |
+
int_type overflow (int_type c = traits::eof()) override;
|
| 88 |
|
| 89 |
+
basic_streambuf<charT, traits>* setbuf(char_type* s,
|
| 90 |
+
streamsize n) override;
|
| 91 |
+
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 92 |
+
ios_base::openmode which
|
| 93 |
+
= ios_base::in | ios_base::out) override;
|
| 94 |
+
pos_type seekpos(pos_type sp,
|
| 95 |
+
ios_base::openmode which
|
| 96 |
+
= ios_base::in | ios_base::out) override;
|
| 97 |
+
int sync() override;
|
| 98 |
+
void imbue(const locale& loc) override;
|
| 99 |
};
|
| 100 |
|
| 101 |
template <class charT, class traits>
|
| 102 |
void swap(basic_filebuf<charT, traits>& x,
|
| 103 |
basic_filebuf<charT, traits>& y);
|
|
|
|
| 107 |
The class `basic_filebuf<charT, traits>` associates both the input
|
| 108 |
sequence and the output sequence with a file.
|
| 109 |
|
| 110 |
The restrictions on reading and writing a sequence controlled by an
|
| 111 |
object of class `basic_filebuf<charT, traits>` are the same as for
|
| 112 |
+
reading and writing with the C standard library `FILE`s.
|
| 113 |
|
| 114 |
In particular:
|
| 115 |
|
| 116 |
- If the file is not open for reading the input sequence cannot be read.
|
| 117 |
- If the file is not open for writing the output sequence cannot be
|
| 118 |
written.
|
| 119 |
- A joint file position is maintained for both the input sequence and
|
| 120 |
the output sequence.
|
| 121 |
|
| 122 |
An instance of `basic_filebuf` behaves as described in [[filebuf]]
|
| 123 |
+
provided `traits::pos_type` is `fpos<traits::{}state_type>`. Otherwise
|
| 124 |
+
the behavior is undefined.
|
| 125 |
|
| 126 |
In order to support file I/O and multibyte/wide character conversion,
|
| 127 |
conversions are performed using members of a facet, referred to as
|
| 128 |
`a_codecvt` in following sections, obtained as if by
|
| 129 |
|
|
|
|
| 140 |
|
| 141 |
*Effects:* Constructs an object of class `basic_filebuf<charT, traits>`,
|
| 142 |
initializing the base class with
|
| 143 |
`basic_streambuf<charT, traits>()` ([[streambuf.cons]]).
|
| 144 |
|
| 145 |
+
*Postconditions:* `is_open() == false`.
|
| 146 |
|
| 147 |
``` cpp
|
| 148 |
basic_filebuf(basic_filebuf&& rhs);
|
| 149 |
```
|
| 150 |
|
|
|
|
| 187 |
|
| 188 |
``` cpp
|
| 189 |
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 190 |
```
|
| 191 |
|
| 192 |
+
*Effects:* Calls `close()` then move assigns from `rhs`. After the move
|
| 193 |
+
assignment `*this` has the observable state it would have had if it had
|
| 194 |
+
been move constructed from `rhs` (see [[filebuf.cons]]).
|
| 195 |
|
| 196 |
*Returns:* `*this`.
|
| 197 |
|
| 198 |
``` cpp
|
| 199 |
void swap(basic_filebuf& rhs);
|
|
|
|
| 205 |
template <class charT, class traits>
|
| 206 |
void swap(basic_filebuf<charT, traits>& x,
|
| 207 |
basic_filebuf<charT, traits>& y);
|
| 208 |
```
|
| 209 |
|
| 210 |
+
*Effects:* As if by `x.swap(y)`.
|
| 211 |
|
| 212 |
#### Member functions <a id="filebuf.members">[[filebuf.members]]</a>
|
| 213 |
|
| 214 |
``` cpp
|
| 215 |
bool is_open() const;
|
|
|
|
| 217 |
|
| 218 |
*Returns:* `true` if a previous call to `open` succeeded (returned a
|
| 219 |
non-null value) and there has been no intervening call to close.
|
| 220 |
|
| 221 |
``` cpp
|
| 222 |
+
basic_filebuf* open(const char* s, ios_base::openmode mode);
|
| 223 |
+
basic_filebuf* open(const filesystem::path::value_type* s,
|
| 224 |
+
ios_base::openmode mode); // wide systems only; see [fstream.syn]
|
| 225 |
```
|
| 226 |
|
| 227 |
*Effects:* If `is_open() != false`, returns a null pointer. Otherwise,
|
| 228 |
initializes the `filebuf` as required. It then opens a file, if
|
| 229 |
possible, whose name is the NTBS`s` (as if by calling
|
| 230 |
+
`fopen(s, modstr)`). The NTBS`modstr` is determined from
|
| 231 |
`mode & ~ios_base::ate` as indicated in
|
| 232 |
Table [[tab:iostreams.file.open.modes]]. If `mode` is not some
|
| 233 |
combination of flags shown in the table then the open fails.
|
| 234 |
|
| 235 |
**Table: File open modes** <a id="tab:iostreams.file.open.modes">[tab:iostreams.file.open.modes]</a>
|
|
|
|
| 255 |
| + | + | | | + | `"a+b"` |
|
| 256 |
|
| 257 |
|
| 258 |
If the open operation succeeds and `(mode & ios_base::ate) != 0`,
|
| 259 |
positions the file to the end (as if by calling
|
| 260 |
+
`fseek(file, 0, SEEK_END)`).[^40]
|
| 261 |
|
| 262 |
If the repositioning operation fails, calls `close()` and returns a null
|
| 263 |
pointer to indicate failure.
|
| 264 |
|
| 265 |
*Returns:* `this` if successful, a null pointer otherwise.
|
| 266 |
|
| 267 |
``` cpp
|
| 268 |
+
basic_filebuf* open(const string& s, ios_base::openmode mode);
|
| 269 |
+
basic_filebuf* open(const filesystem::path& s, ios_base::openmode mode);
|
| 270 |
```
|
| 271 |
|
| 272 |
*Returns:* `open(s.c_str(), mode);`
|
| 273 |
|
| 274 |
``` cpp
|
| 275 |
+
basic_filebuf* close();
|
| 276 |
```
|
| 277 |
|
| 278 |
*Effects:* If `is_open() == false`, returns a null pointer. If a put
|
| 279 |
area exists, calls `overflow(traits::eof())` to flush characters. If the
|
| 280 |
last virtual member function called on `*this` (between `underflow`,
|
| 281 |
`overflow`, `seekoff`, and `seekpos`) was `overflow` then calls
|
| 282 |
`a_codecvt.unshift` (possibly several times) to determine a termination
|
| 283 |
sequence, inserts those characters and calls `overflow(traits::eof())`
|
| 284 |
again. Finally, regardless of whether any of the preceding calls fails
|
| 285 |
or throws an exception, the function closes the file (as if by calling
|
| 286 |
+
`fclose(file)`). If any of the calls made by the function, including
|
| 287 |
+
`fclose`, fails, `close` fails by returning a null pointer. If one of
|
| 288 |
+
these calls throws an exception, the exception is caught and rethrown
|
| 289 |
+
after closing the file.
|
| 290 |
|
| 291 |
*Returns:* `this` on success, a null pointer otherwise.
|
| 292 |
|
| 293 |
+
*Postconditions:* `is_open() == false`.
|
| 294 |
|
| 295 |
#### Overridden virtual functions <a id="filebuf.virtuals">[[filebuf.virtuals]]</a>
|
| 296 |
|
| 297 |
``` cpp
|
| 298 |
+
streamsize showmanyc() override;
|
| 299 |
```
|
| 300 |
|
| 301 |
*Effects:* Behaves the same as
|
| 302 |
`basic_streambuf::showmanyc()` ([[streambuf.virtuals]]).
|
| 303 |
|
| 304 |
*Remarks:* An implementation might well provide an overriding definition
|
| 305 |
for this function signature if it can determine that more characters can
|
| 306 |
be read from the input sequence.
|
| 307 |
|
| 308 |
``` cpp
|
| 309 |
+
int_type underflow() override;
|
| 310 |
```
|
| 311 |
|
| 312 |
*Effects:* Behaves according to the description of
|
| 313 |
`basic_streambuf<charT, traits>::underflow()`, with the specialization
|
| 314 |
that a sequence of characters is read from the input sequence as if by
|
| 315 |
reading from the associated file into an internal buffer (`extern_buf`)
|
| 316 |
+
and then as if by doing:
|
| 317 |
|
| 318 |
``` cpp
|
| 319 |
char extern_buf[XSIZE];
|
| 320 |
char* extern_end;
|
| 321 |
charT intern_buf[ISIZE];
|
|
|
|
| 329 |
(`fpos_t`) corresponding to each character between `intern_buf` and
|
| 330 |
`intern_end`. If the value of `r` indicates that `a_codecvt.in()` ran
|
| 331 |
out of space in `intern_buf`, retry with a larger `intern_buf`.
|
| 332 |
|
| 333 |
``` cpp
|
| 334 |
+
int_type uflow() override;
|
| 335 |
```
|
| 336 |
|
| 337 |
*Effects:* Behaves according to the description of
|
| 338 |
+
`basic_streambuf<charT, traits>::uflow()`, with the specialization that
|
| 339 |
+
a sequence of characters is read from the input with the same method as
|
| 340 |
used by `underflow`.
|
| 341 |
|
| 342 |
``` cpp
|
| 343 |
+
int_type pbackfail(int_type c = traits::eof()) override;
|
| 344 |
```
|
| 345 |
|
| 346 |
*Effects:* Puts back the character designated by `c` to the input
|
| 347 |
sequence, if possible, in one of three ways:
|
| 348 |
|
|
|
|
| 370 |
If the function can succeed in more than one of these ways, it is
|
| 371 |
unspecified which way is chosen. The function can alter the number of
|
| 372 |
putback positions available as a result of any call.
|
| 373 |
|
| 374 |
``` cpp
|
| 375 |
+
int_type overflow(int_type c = traits::eof()) override;
|
| 376 |
```
|
| 377 |
|
| 378 |
*Effects:* Behaves according to the description of
|
| 379 |
`basic_streambuf<charT, traits>::overflow(c)`, except that the behavior
|
| 380 |
of “consuming characters” is performed by first converting as if by:
|
|
|
|
| 403 |
|
| 404 |
*Returns:* `traits::not_eof(c)` to indicate success, and `traits::eof()`
|
| 405 |
to indicate failure. If `is_open() == false`, the function always fails.
|
| 406 |
|
| 407 |
``` cpp
|
| 408 |
+
basic_streambuf* setbuf(char_type* s, streamsize n) override;
|
| 409 |
```
|
| 410 |
|
| 411 |
*Effects:* If `setbuf(0, 0)` is called on a stream before any I/O has
|
| 412 |
occurred on that stream, the stream becomes unbuffered. Otherwise the
|
| 413 |
results are *implementation-defined*. “Unbuffered” means that `pbase()`
|
| 414 |
and `pptr()` always return null and output to the file should appear as
|
| 415 |
soon as possible.
|
| 416 |
|
| 417 |
``` cpp
|
| 418 |
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 419 |
+
ios_base::openmode which
|
| 420 |
+
= ios_base::in | ios_base::out) override;
|
| 421 |
```
|
| 422 |
|
| 423 |
*Effects:* Let `width` denote `a_codecvt.encoding()`. If
|
| 424 |
`is_open() == false`, or `off != 0 && width <= 0`, then the positioning
|
| 425 |
operation fails. Otherwise, if `way != basic_ios::cur` or `off != 0`,
|
| 426 |
and if the last operation was output, then update the output sequence
|
| 427 |
and write any unshift sequence. Next, seek to the new position: if
|
| 428 |
+
`width > 0`, call `fseek(file, width * off, whence)`, otherwise call
|
| 429 |
+
`fseek(file, 0, whence)`.
|
| 430 |
|
| 431 |
*Remarks:* “The last operation was output” means either the last virtual
|
| 432 |
operation was overflow or the put buffer is non-empty. “Write any
|
| 433 |
unshift sequence” means, if `width` if less than zero then call
|
| 434 |
`a_codecvt.unshift(state, xbuf, xbuf+XSIZE, xbuf_end)` and output the
|
|
|
|
| 450 |
fails, or if the object cannot represent the resultant stream position,
|
| 451 |
returns `pos_type(off_type(-1))`.
|
| 452 |
|
| 453 |
``` cpp
|
| 454 |
pos_type seekpos(pos_type sp,
|
| 455 |
+
ios_base::openmode which
|
| 456 |
+
= ios_base::in | ios_base::out) override;
|
| 457 |
```
|
| 458 |
|
| 459 |
Alters the file position, if possible, to correspond to the position
|
| 460 |
stored in `sp` (as described below). Altering the file position performs
|
| 461 |
as follows:
|
| 462 |
|
| 463 |
1. if `(om & ios_base::out) != 0`, then update the output sequence and
|
| 464 |
write any unshift sequence;
|
| 465 |
+
2. set the file position to `sp` as if by a call to `fsetpos`;
|
| 466 |
3. if `(om & ios_base::in) != 0`, then update the input sequence;
|
| 467 |
|
| 468 |
where `om` is the open mode passed to the last call to `open()`. The
|
| 469 |
+
operation fails if `is_open()` returns `false`.
|
| 470 |
|
| 471 |
If `sp` is an invalid stream position, or if the function positions
|
| 472 |
neither sequence, the positioning operation fails. If `sp` has not been
|
| 473 |
obtained by a previous successful call to one of the positioning
|
| 474 |
functions (`seekoff` or `seekpos`) on the same file the effects are
|
| 475 |
undefined.
|
| 476 |
|
| 477 |
*Returns:* `sp` on success. Otherwise returns `pos_type(off_type(-1))`.
|
| 478 |
|
| 479 |
``` cpp
|
| 480 |
+
int sync() override;
|
| 481 |
```
|
| 482 |
|
| 483 |
*Effects:* If a put area exists, calls `filebuf::overflow` to write the
|
| 484 |
+
characters to the file, then flushes the file as if by calling
|
| 485 |
+
`fflush(file)`. If a get area exists, the effect is
|
| 486 |
*implementation-defined*.
|
| 487 |
|
| 488 |
``` cpp
|
| 489 |
+
void imbue(const locale& loc) override;
|
| 490 |
```
|
| 491 |
|
| 492 |
+
*Requires:* If the file is not positioned at its beginning and the
|
| 493 |
+
encoding of the current locale as determined by `a_codecvt.encoding()`
|
| 494 |
+
is state-dependent ([[locale.codecvt.virtuals]]) then that facet is the
|
| 495 |
same as the corresponding facet of `loc`.
|
| 496 |
|
| 497 |
*Effects:* Causes characters inserted or extracted after this call to be
|
| 498 |
converted according to `loc` until another call of `imbue`.
|
| 499 |
|
| 500 |
+
*Remarks:* This may require reconversion of previously converted
|
| 501 |
+
characters. This in turn may require the implementation to be able to
|
| 502 |
+
reconstruct the original contents of the file.
|
| 503 |
|
| 504 |
+
### Class template `basic_ifstream` <a id="ifstream">[[ifstream]]</a>
|
| 505 |
|
| 506 |
``` cpp
|
| 507 |
namespace std {
|
| 508 |
template <class charT, class traits = char_traits<charT>>
|
| 509 |
class basic_ifstream : public basic_istream<charT, traits> {
|
| 510 |
public:
|
| 511 |
+
using char_type = charT;
|
| 512 |
+
using int_type = typename traits::int_type;
|
| 513 |
+
using pos_type = typename traits::pos_type;
|
| 514 |
+
using off_type = typename traits::off_type;
|
| 515 |
+
using traits_type = traits;
|
| 516 |
|
| 517 |
+
// [ifstream.cons], constructors
|
| 518 |
basic_ifstream();
|
| 519 |
explicit basic_ifstream(const char* s,
|
| 520 |
ios_base::openmode mode = ios_base::in);
|
| 521 |
+
explicit basic_ifstream(const filesystem::path::value_type* s,
|
| 522 |
+
ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
|
| 523 |
explicit basic_ifstream(const string& s,
|
| 524 |
ios_base::openmode mode = ios_base::in);
|
| 525 |
+
explicit basic_ifstream(const filesystem::path& s,
|
| 526 |
+
ios_base::openmode mode = ios_base::in);
|
| 527 |
basic_ifstream(const basic_ifstream& rhs) = delete;
|
| 528 |
basic_ifstream(basic_ifstream&& rhs);
|
| 529 |
|
| 530 |
+
// [ifstream.assign], assign and swap
|
| 531 |
basic_ifstream& operator=(const basic_ifstream& rhs) = delete;
|
| 532 |
basic_ifstream& operator=(basic_ifstream&& rhs);
|
| 533 |
void swap(basic_ifstream& rhs);
|
| 534 |
|
| 535 |
+
// [ifstream.members], members
|
| 536 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 537 |
|
| 538 |
bool is_open() const;
|
| 539 |
void open(const char* s, ios_base::openmode mode = ios_base::in);
|
| 540 |
+
void open(const filesystem::path::value_type* s,
|
| 541 |
+
ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
|
| 542 |
void open(const string& s, ios_base::openmode mode = ios_base::in);
|
| 543 |
+
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);
|
| 544 |
void close();
|
| 545 |
private:
|
| 546 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 547 |
};
|
| 548 |
|
|
|
|
| 563 |
|
| 564 |
``` cpp
|
| 565 |
basic_ifstream();
|
| 566 |
```
|
| 567 |
|
| 568 |
+
*Effects:* Constructs an object of class
|
| 569 |
+
`basic_ifstream<charT, traits>`, initializing the base class with
|
| 570 |
+
`basic_istream(&sb)` and initializing `sb` with
|
| 571 |
+
`basic_filebuf<charT, traits>())` ([[istream.cons]], [[filebuf.cons]]).
|
| 572 |
|
| 573 |
``` cpp
|
| 574 |
explicit basic_ifstream(const char* s,
|
| 575 |
ios_base::openmode mode = ios_base::in);
|
| 576 |
+
explicit basic_ifstream(const filesystem::path::value_type* s,
|
| 577 |
+
ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
|
| 578 |
```
|
| 579 |
|
| 580 |
*Effects:* Constructs an object of class `basic_ifstream`, initializing
|
| 581 |
the base class with `basic_istream(&sb)` and initializing `sb` with
|
| 582 |
`basic_filebuf<charT, traits>())` ([[istream.cons]], [[filebuf.cons]]),
|
|
|
|
| 584 |
returns a null pointer, calls `setstate(failbit)`.
|
| 585 |
|
| 586 |
``` cpp
|
| 587 |
explicit basic_ifstream(const string& s,
|
| 588 |
ios_base::openmode mode = ios_base::in);
|
| 589 |
+
explicit basic_ifstream(const filesystem::path& s,
|
| 590 |
+
ios_base::openmode mode = ios_base::in);
|
| 591 |
```
|
| 592 |
|
| 593 |
+
*Effects:* The same as `basic_ifstream(s.c_str(), mode)`.
|
| 594 |
|
| 595 |
``` cpp
|
| 596 |
basic_ifstream(basic_ifstream&& rhs);
|
| 597 |
```
|
| 598 |
|
|
|
|
| 623 |
template <class charT, class traits>
|
| 624 |
void swap(basic_ifstream<charT, traits>& x,
|
| 625 |
basic_ifstream<charT, traits>& y);
|
| 626 |
```
|
| 627 |
|
| 628 |
+
*Effects:* As if by `x.swap(y)`.
|
| 629 |
|
| 630 |
#### Member functions <a id="ifstream.members">[[ifstream.members]]</a>
|
| 631 |
|
| 632 |
``` cpp
|
| 633 |
basic_filebuf<charT, traits>* rdbuf() const;
|
|
|
|
| 641 |
|
| 642 |
*Returns:* `rdbuf()->is_open()`.
|
| 643 |
|
| 644 |
``` cpp
|
| 645 |
void open(const char* s, ios_base::openmode mode = ios_base::in);
|
| 646 |
+
void open(const filesystem::path::value_type* s,
|
| 647 |
+
ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
|
| 648 |
```
|
| 649 |
|
| 650 |
*Effects:* Calls `rdbuf()->open(s, mode | ios_base::in)`. If that
|
| 651 |
function does not return a null pointer calls `clear()`, otherwise calls
|
| 652 |
+
`setstate(failbit)` (which may throw `ios_base::failure`)
|
| 653 |
+
([[iostate.flags]]).
|
| 654 |
|
| 655 |
``` cpp
|
| 656 |
void open(const string& s, ios_base::openmode mode = ios_base::in);
|
| 657 |
+
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);
|
| 658 |
```
|
| 659 |
|
| 660 |
+
*Effects:* Calls `open(s.c_str(), mode)`.
|
| 661 |
|
| 662 |
``` cpp
|
| 663 |
void close();
|
| 664 |
```
|
| 665 |
|
| 666 |
*Effects:* Calls `rdbuf()->close()` and, if that function returns a null
|
| 667 |
pointer, calls `setstate(failbit)` (which may throw
|
| 668 |
+
`ios_base::failure`) ([[iostate.flags]]).
|
| 669 |
|
| 670 |
+
### Class template `basic_ofstream` <a id="ofstream">[[ofstream]]</a>
|
| 671 |
|
| 672 |
``` cpp
|
| 673 |
namespace std {
|
| 674 |
template <class charT, class traits = char_traits<charT>>
|
| 675 |
class basic_ofstream : public basic_ostream<charT, traits> {
|
| 676 |
public:
|
| 677 |
+
using char_type = charT;
|
| 678 |
+
using int_type = typename traits::int_type;
|
| 679 |
+
using pos_type = typename traits::pos_type;
|
| 680 |
+
using off_type = typename traits::off_type;
|
| 681 |
+
using traits_type = traits;
|
| 682 |
|
| 683 |
+
// [ofstream.cons], constructors
|
| 684 |
basic_ofstream();
|
| 685 |
explicit basic_ofstream(const char* s,
|
| 686 |
ios_base::openmode mode = ios_base::out);
|
| 687 |
+
explicit basic_ofstream(const filesystem::path::value_type* s,
|
| 688 |
+
ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
|
| 689 |
explicit basic_ofstream(const string& s,
|
| 690 |
ios_base::openmode mode = ios_base::out);
|
| 691 |
+
explicit basic_ofstream(const filesystem::path& s,
|
| 692 |
+
ios_base::openmode mode = ios_base::out);
|
| 693 |
basic_ofstream(const basic_ofstream& rhs) = delete;
|
| 694 |
basic_ofstream(basic_ofstream&& rhs);
|
| 695 |
|
| 696 |
+
// [ofstream.assign], assign and swap
|
| 697 |
basic_ofstream& operator=(const basic_ofstream& rhs) = delete;
|
| 698 |
basic_ofstream& operator=(basic_ofstream&& rhs);
|
| 699 |
void swap(basic_ofstream& rhs);
|
| 700 |
|
| 701 |
+
// [ofstream.members], members
|
| 702 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 703 |
|
| 704 |
bool is_open() const;
|
| 705 |
void open(const char* s, ios_base::openmode mode = ios_base::out);
|
| 706 |
+
void open(const filesystem::path::value_type* s,
|
| 707 |
+
ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
|
| 708 |
void open(const string& s, ios_base::openmode mode = ios_base::out);
|
| 709 |
+
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
|
| 710 |
void close();
|
| 711 |
private:
|
| 712 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 713 |
};
|
| 714 |
|
|
|
|
| 729 |
|
| 730 |
``` cpp
|
| 731 |
basic_ofstream();
|
| 732 |
```
|
| 733 |
|
| 734 |
+
*Effects:* Constructs an object of class
|
| 735 |
+
`basic_ofstream<charT, traits>`, initializing the base class with
|
| 736 |
+
`basic_ostream(&sb)` and initializing `sb` with
|
| 737 |
+
`basic_filebuf<charT, traits>())` ([[ostream.cons]], [[filebuf.cons]]).
|
| 738 |
|
| 739 |
``` cpp
|
| 740 |
explicit basic_ofstream(const char* s,
|
| 741 |
ios_base::openmode mode = ios_base::out);
|
| 742 |
+
explicit basic_ofstream(const filesystem::path::value_type* s,
|
| 743 |
+
ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
|
| 744 |
```
|
| 745 |
|
| 746 |
+
*Effects:* Constructs an object of class
|
| 747 |
+
`basic_ofstream<charT, traits>`, initializing the base class with
|
| 748 |
+
`basic_ostream(&sb)` and initializing `sb` with
|
| 749 |
+
`basic_filebuf<charT, traits>())` ([[ostream.cons]], [[filebuf.cons]]),
|
| 750 |
+
then calls `rdbuf()->open(s, mode | ios_base::out)`. If that function
|
| 751 |
+
returns a null pointer, calls `setstate(failbit)`.
|
| 752 |
|
| 753 |
``` cpp
|
| 754 |
explicit basic_ofstream(const string& s,
|
| 755 |
ios_base::openmode mode = ios_base::out);
|
| 756 |
+
explicit basic_ofstream(const filesystem::path& s,
|
| 757 |
+
ios_base::openmode mode = ios_base::out);
|
| 758 |
```
|
| 759 |
|
| 760 |
+
*Effects:* The same as `basic_ofstream(s.c_str(), mode)`.
|
| 761 |
|
| 762 |
``` cpp
|
| 763 |
basic_ofstream(basic_ofstream&& rhs);
|
| 764 |
```
|
| 765 |
|
|
|
|
| 790 |
template <class charT, class traits>
|
| 791 |
void swap(basic_ofstream<charT, traits>& x,
|
| 792 |
basic_ofstream<charT, traits>& y);
|
| 793 |
```
|
| 794 |
|
| 795 |
+
*Effects:* As if by `x.swap(y)`.
|
| 796 |
|
| 797 |
#### Member functions <a id="ofstream.members">[[ofstream.members]]</a>
|
| 798 |
|
| 799 |
``` cpp
|
| 800 |
basic_filebuf<charT, traits>* rdbuf() const;
|
|
|
|
| 808 |
|
| 809 |
*Returns:* `rdbuf()->is_open()`.
|
| 810 |
|
| 811 |
``` cpp
|
| 812 |
void open(const char* s, ios_base::openmode mode = ios_base::out);
|
| 813 |
+
void open(const filesystem::path::value_type* s,
|
| 814 |
+
ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
|
| 815 |
```
|
| 816 |
|
| 817 |
*Effects:* Calls `rdbuf()->open(s, mode | ios_base::out)`. If that
|
| 818 |
function does not return a null pointer calls `clear()`, otherwise calls
|
| 819 |
+
`setstate(failbit)` (which may throw `ios_base::failure`)
|
| 820 |
+
([[iostate.flags]]).
|
| 821 |
|
| 822 |
``` cpp
|
| 823 |
void close();
|
| 824 |
```
|
| 825 |
|
| 826 |
*Effects:* Calls `rdbuf()->close()` and, if that function fails (returns
|
| 827 |
a null pointer), calls `setstate(failbit)` (which may throw
|
| 828 |
+
`ios_base::failure`) ([[iostate.flags]]).
|
| 829 |
|
| 830 |
``` cpp
|
| 831 |
void open(const string& s, ios_base::openmode mode = ios_base::out);
|
| 832 |
+
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
|
| 833 |
```
|
| 834 |
|
| 835 |
+
*Effects:* Calls `open(s.c_str(), mode)`.
|
| 836 |
|
| 837 |
+
### Class template `basic_fstream` <a id="fstream">[[fstream]]</a>
|
| 838 |
|
| 839 |
``` cpp
|
| 840 |
namespace std {
|
| 841 |
template <class charT, class traits = char_traits<charT>>
|
| 842 |
+
class basic_fstream : public basic_iostream<charT, traits> {
|
|
|
|
|
|
|
| 843 |
public:
|
| 844 |
+
using char_type = charT;
|
| 845 |
+
using int_type = typename traits::int_type;
|
| 846 |
+
using pos_type = typename traits::pos_type;
|
| 847 |
+
using off_type = typename traits::off_type;
|
| 848 |
+
using traits_type = traits;
|
| 849 |
|
| 850 |
+
// [fstream.cons], constructors
|
| 851 |
basic_fstream();
|
| 852 |
+
explicit basic_fstream(
|
| 853 |
+
const char* s,
|
| 854 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 855 |
+
explicit basic_fstream(
|
| 856 |
+
const std::filesystem::path::value_type* s,
|
| 857 |
+
ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
|
| 858 |
+
explicit basic_fstream(
|
| 859 |
+
const string& s,
|
| 860 |
+
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 861 |
+
explicit basic_fstream(
|
| 862 |
+
const filesystem::path& s,
|
| 863 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 864 |
basic_fstream(const basic_fstream& rhs) = delete;
|
| 865 |
basic_fstream(basic_fstream&& rhs);
|
| 866 |
|
| 867 |
+
// [fstream.assign], assign and swap
|
| 868 |
basic_fstream& operator=(const basic_fstream& rhs) = delete;
|
| 869 |
basic_fstream& operator=(basic_fstream&& rhs);
|
| 870 |
void swap(basic_fstream& rhs);
|
| 871 |
|
| 872 |
+
// [fstream.members], members
|
| 873 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 874 |
bool is_open() const;
|
| 875 |
+
void open(
|
| 876 |
+
const char* s,
|
| 877 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 878 |
+
void open(
|
| 879 |
+
const std::filesystem::path::value_type* s,
|
| 880 |
+
ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
|
| 881 |
+
void open(
|
| 882 |
+
const string& s,
|
| 883 |
+
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 884 |
+
void open(
|
| 885 |
+
const filesystem::path& s,
|
| 886 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 887 |
void close();
|
| 888 |
|
| 889 |
private:
|
| 890 |
basic_filebuf<charT, traits> sb; // exposition only
|
|
|
|
| 895 |
basic_fstream<charT, traits>& y);
|
| 896 |
}
|
| 897 |
```
|
| 898 |
|
| 899 |
The class template `basic_fstream<charT, traits>` supports reading and
|
| 900 |
+
writing from named files. It uses a `basic_filebuf<charT, traits>`
|
| 901 |
+
object to control the associated sequences. For the sake of exposition,
|
| 902 |
+
the maintained data is presented here as:
|
| 903 |
|
| 904 |
- `sb`, the `basic_filebuf` object.
|
| 905 |
|
| 906 |
#### `basic_fstream` constructors <a id="fstream.cons">[[fstream.cons]]</a>
|
| 907 |
|
|
|
|
| 912 |
*Effects:* Constructs an object of class `basic_fstream<charT, traits>`,
|
| 913 |
initializing the base class with `basic_iostream(&sb)` and initializing
|
| 914 |
`sb` with `basic_filebuf<charT, traits>()`.
|
| 915 |
|
| 916 |
``` cpp
|
| 917 |
+
explicit basic_fstream(
|
| 918 |
+
const char* s,
|
| 919 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 920 |
+
explicit basic_fstream(
|
| 921 |
+
const filesystem::path::value_type* s,
|
| 922 |
+
ios_base::openmode mode = ios_base::in | ios_base::out); // wide systems only; see [fstream.syn]
|
| 923 |
```
|
| 924 |
|
| 925 |
*Effects:* Constructs an object of class `basic_fstream<charT, traits>`,
|
| 926 |
initializing the base class with `basic_iostream(&sb)` and initializing
|
| 927 |
`sb` with `basic_filebuf<charT, traits>()`. Then calls
|
| 928 |
`rdbuf()->open(s, mode)`. If that function returns a null pointer, calls
|
| 929 |
`setstate(failbit)`.
|
| 930 |
|
| 931 |
``` cpp
|
| 932 |
+
explicit basic_fstream(
|
| 933 |
+
const string& s,
|
| 934 |
+
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 935 |
+
explicit basic_fstream(
|
| 936 |
+
const filesystem::path& s,
|
| 937 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 938 |
```
|
| 939 |
|
| 940 |
+
*Effects:* The same as `basic_fstream(s.c_str(), mode)`.
|
| 941 |
|
| 942 |
``` cpp
|
| 943 |
basic_fstream(basic_fstream&& rhs);
|
| 944 |
```
|
| 945 |
|
|
|
|
| 970 |
template <class charT, class traits>
|
| 971 |
void swap(basic_fstream<charT, traits>& x,
|
| 972 |
basic_fstream<charT, traits>& y);
|
| 973 |
```
|
| 974 |
|
| 975 |
+
*Effects:* As if by `x.swap(y)`.
|
| 976 |
|
| 977 |
#### Member functions <a id="fstream.members">[[fstream.members]]</a>
|
| 978 |
|
| 979 |
``` cpp
|
| 980 |
basic_filebuf<charT, traits>* rdbuf() const;
|
|
|
|
| 987 |
```
|
| 988 |
|
| 989 |
*Returns:* `rdbuf()->is_open()`.
|
| 990 |
|
| 991 |
``` cpp
|
| 992 |
+
void open(
|
| 993 |
+
const char* s,
|
| 994 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 995 |
+
void open(
|
| 996 |
+
const filesystem::path::value_type* s,
|
| 997 |
+
ios_base::openmode mode = ios_base::in | ios_base::out); // wide systems only; see [fstream.syn]
|
| 998 |
```
|
| 999 |
|
| 1000 |
*Effects:* Calls `rdbuf()->open(s, mode)`. If that function does not
|
| 1001 |
return a null pointer calls `clear()`, otherwise calls
|
| 1002 |
+
`setstate(failbit)` (which may throw
|
| 1003 |
`ios_base::failure`) ([[iostate.flags]]).
|
| 1004 |
|
| 1005 |
``` cpp
|
| 1006 |
+
void open(
|
| 1007 |
+
const string& s,
|
| 1008 |
+
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 1009 |
+
void open(
|
| 1010 |
+
const filesystem::path& s,
|
| 1011 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 1012 |
```
|
| 1013 |
|
| 1014 |
+
*Effects:* Calls `open(s.c_str(), mode)`.
|
| 1015 |
|
| 1016 |
``` cpp
|
| 1017 |
void close();
|
| 1018 |
```
|
| 1019 |
|
| 1020 |
+
*Effects:* Calls `rdbuf()->close()` and, if that function returns a null
|
| 1021 |
+
pointer, calls `setstate(failbit)` (which may throw
|
| 1022 |
+
`ios_base::failure`) ([[iostate.flags]]).
|
| 1023 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|