- tmp/tmps2tof32m/{from.md → to.md} +110 -75
tmp/tmps2tof32m/{from.md → to.md}
RENAMED
|
@@ -4,25 +4,41 @@
|
|
| 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 |
|
|
@@ -35,18 +51,20 @@ 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 subclause [[file.streams]], member functions taking arguments of
|
| 40 |
-
`const filesystem::path::value_type*` are only
|
| 41 |
-
|
| 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:
|
|
@@ -60,11 +78,11 @@ namespace std {
|
|
| 60 |
basic_filebuf();
|
| 61 |
basic_filebuf(const basic_filebuf&) = delete;
|
| 62 |
basic_filebuf(basic_filebuf&& rhs);
|
| 63 |
virtual ~basic_filebuf();
|
| 64 |
|
| 65 |
-
// [filebuf.assign],
|
| 66 |
basic_filebuf& operator=(const basic_filebuf&) = delete;
|
| 67 |
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 68 |
void swap(basic_filebuf& rhs);
|
| 69 |
|
| 70 |
// [filebuf.members], members
|
|
@@ -95,14 +113,10 @@ namespace std {
|
|
| 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);
|
| 104 |
}
|
| 105 |
```
|
| 106 |
|
| 107 |
The class `basic_filebuf<charT, traits>` associates both the input
|
| 108 |
sequence and the output sequence with a file.
|
|
@@ -200,12 +214,11 @@ void swap(basic_filebuf& rhs);
|
|
| 200 |
|
| 201 |
*Effects:* Exchanges the state of `*this` and `rhs`.
|
| 202 |
|
| 203 |
``` cpp
|
| 204 |
template<class charT, class traits>
|
| 205 |
-
void swap(basic_filebuf<charT, traits>& x,
|
| 206 |
-
basic_filebuf<charT, traits>& y);
|
| 207 |
```
|
| 208 |
|
| 209 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 210 |
|
| 211 |
#### Member functions <a id="filebuf.members">[[filebuf.members]]</a>
|
|
@@ -232,35 +245,42 @@ argument determined from `mode & ~ios_base::ate` as indicated in
|
|
| 232 |
[[filebuf.open.modes]]. If `mode` is not some combination of flags shown
|
| 233 |
in the table then the open fails.
|
| 234 |
|
| 235 |
**Table: File open modes** <a id="filebuf.open.modes">[filebuf.open.modes]</a>
|
| 236 |
|
| 237 |
-
| `binary` | `in` | `out` | `trunc` | `app` |
|
| 238 |
-
| -------- | ---- | ----- | ------- | ----- | --- | ------------------ |
|
| 239 |
-
| | | + | | | `"w"`
|
| 240 |
-
| | | + | | +
|
| 241 |
-
| | |
|
| 242 |
-
| | | + | + | | `"
|
| 243 |
-
| | +
|
| 244 |
-
| |
|
| 245 |
-
| | + |
|
| 246 |
-
| | + | + | |
|
| 247 |
-
| | + |
|
| 248 |
-
| +
|
| 249 |
-
| +
|
| 250 |
-
| +
|
| 251 |
-
| + | +
|
| 252 |
-
| + |
|
| 253 |
-
| + |
|
| 254 |
-
| + | +
|
| 255 |
-
| + | +
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
|
| 258 |
If the open operation succeeds and `ios_base::ate` is set in `mode`,
|
| 259 |
positions the file to the end (as if by calling
|
| 260 |
`fseek(file, 0, SEEK_END)`, where `file` is the pointer returned by
|
| 261 |
-
calling `fopen`).
|
| 262 |
|
| 263 |
If the repositioning operation fails, calls `close()` and returns a null
|
| 264 |
pointer to indicate failure.
|
| 265 |
|
| 266 |
*Returns:* `this` if successful, a null pointer otherwise.
|
|
@@ -287,25 +307,25 @@ or throws an exception, the function closes the file (as if by calling
|
|
| 287 |
`fclose(file)`). If any of the calls made by the function, including
|
| 288 |
`fclose`, fails, `close` fails by returning a null pointer. If one of
|
| 289 |
these calls throws an exception, the exception is caught and rethrown
|
| 290 |
after closing the file.
|
| 291 |
|
|
|
|
|
|
|
| 292 |
*Returns:* `this` on success, a null pointer otherwise.
|
| 293 |
|
| 294 |
-
*Ensures:* `is_open() == false`.
|
| 295 |
-
|
| 296 |
#### Overridden virtual functions <a id="filebuf.virtuals">[[filebuf.virtuals]]</a>
|
| 297 |
|
| 298 |
``` cpp
|
| 299 |
streamsize showmanyc() override;
|
| 300 |
```
|
| 301 |
|
| 302 |
*Effects:* Behaves the same as `basic_streambuf::showmanyc()`
|
| 303 |
[[streambuf.virtuals]].
|
| 304 |
|
| 305 |
-
*Remarks:* An implementation
|
| 306 |
-
|
| 307 |
be read from the input sequence.
|
| 308 |
|
| 309 |
``` cpp
|
| 310 |
int_type underflow() override;
|
| 311 |
```
|
|
@@ -427,10 +447,15 @@ operation fails. Otherwise, if `way != basic_ios::cur` or `off != 0`,
|
|
| 427 |
and if the last operation was output, then update the output sequence
|
| 428 |
and write any unshift sequence. Next, seek to the new position: if
|
| 429 |
`width > 0`, call `fseek(file, width * off, whence)`, otherwise call
|
| 430 |
`fseek(file, 0, whence)`.
|
| 431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
*Remarks:* “The last operation was output” means either the last virtual
|
| 433 |
operation was overflow or the put buffer is non-empty. “Write any
|
| 434 |
unshift sequence” means, if `width` if less than zero then call
|
| 435 |
`a_codecvt.unshift(state, xbuf, xbuf+XSIZE, xbuf_end)` and output the
|
| 436 |
resulting unshift sequence. The function determines one of three values
|
|
@@ -443,16 +468,10 @@ for the argument `whence`, of type `int`, as indicated in
|
|
| 443 |
| ---------------- | ------------------ |
|
| 444 |
| `basic_ios::beg` | `SEEK_SET` |
|
| 445 |
| `basic_ios::cur` | `SEEK_CUR` |
|
| 446 |
| `basic_ios::end` | `SEEK_END` |
|
| 447 |
|
| 448 |
-
|
| 449 |
-
*Returns:* A newly constructed `pos_type` object that stores the
|
| 450 |
-
resultant stream position, if possible. If the positioning operation
|
| 451 |
-
fails, or if the object cannot represent the resultant stream position,
|
| 452 |
-
returns `pos_type(off_type(-1))`.
|
| 453 |
-
|
| 454 |
``` cpp
|
| 455 |
pos_type seekpos(pos_type sp,
|
| 456 |
ios_base::openmode which
|
| 457 |
= ios_base::in | ios_base::out) override;
|
| 458 |
```
|
|
@@ -502,10 +521,12 @@ converted according to `loc` until another call of `imbue`.
|
|
| 502 |
characters. This in turn may require the implementation to be able to
|
| 503 |
reconstruct the original contents of the file.
|
| 504 |
|
| 505 |
### Class template `basic_ifstream` <a id="ifstream">[[ifstream]]</a>
|
| 506 |
|
|
|
|
|
|
|
| 507 |
``` cpp
|
| 508 |
namespace std {
|
| 509 |
template<class charT, class traits = char_traits<charT>>
|
| 510 |
class basic_ifstream : public basic_istream<charT, traits> {
|
| 511 |
public:
|
|
@@ -521,18 +542,19 @@ namespace std {
|
|
| 521 |
ios_base::openmode mode = ios_base::in);
|
| 522 |
explicit basic_ifstream(const filesystem::path::value_type* s,
|
| 523 |
ios_base::openmode mode = ios_base::in);// wide systems only; see [fstream.syn]
|
| 524 |
explicit basic_ifstream(const string& s,
|
| 525 |
ios_base::openmode mode = ios_base::in);
|
| 526 |
-
|
| 527 |
-
|
| 528 |
basic_ifstream(const basic_ifstream&) = delete;
|
| 529 |
basic_ifstream(basic_ifstream&& rhs);
|
| 530 |
|
| 531 |
-
// [ifstream.assign], assign and swap
|
| 532 |
basic_ifstream& operator=(const basic_ifstream&) = delete;
|
| 533 |
basic_ifstream& operator=(basic_ifstream&& rhs);
|
|
|
|
|
|
|
| 534 |
void swap(basic_ifstream& rhs);
|
| 535 |
|
| 536 |
// [ifstream.members], members
|
| 537 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 538 |
|
|
@@ -541,17 +563,14 @@ namespace std {
|
|
| 541 |
void open(const filesystem::path::value_type* s,
|
| 542 |
ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
|
| 543 |
void open(const string& s, ios_base::openmode mode = ios_base::in);
|
| 544 |
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);
|
| 545 |
void close();
|
|
|
|
| 546 |
private:
|
| 547 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 548 |
};
|
| 549 |
-
|
| 550 |
-
template<class charT, class traits>
|
| 551 |
-
void swap(basic_ifstream<charT, traits>& x,
|
| 552 |
-
basic_ifstream<charT, traits>& y);
|
| 553 |
}
|
| 554 |
```
|
| 555 |
|
| 556 |
The class `basic_ifstream<charT, traits>` supports reading from named
|
| 557 |
files. It uses a `basic_filebuf<{}charT, traits>` object to control the
|
|
@@ -584,38 +603,44 @@ with `basic_filebuf<charT, traits>()` [[filebuf.cons]], then calls
|
|
| 584 |
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:* Equivalent to: `basic_ifstream(s.c_str(), mode)`.
|
| 594 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
``` cpp
|
| 596 |
basic_ifstream(basic_ifstream&& rhs);
|
| 597 |
```
|
| 598 |
|
| 599 |
*Effects:* Move constructs the base class, and the contained
|
| 600 |
`basic_filebuf`. Then calls
|
| 601 |
`basic_istream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 602 |
contained `basic_filebuf`.
|
| 603 |
|
| 604 |
-
####
|
| 605 |
|
| 606 |
``` cpp
|
| 607 |
void swap(basic_ifstream& rhs);
|
| 608 |
```
|
| 609 |
|
| 610 |
*Effects:* Exchanges the state of `*this` and `rhs` by calling
|
| 611 |
`basic_istream<charT, traits>::swap(rhs)` and `sb.swap(rhs.sb)`.
|
| 612 |
|
| 613 |
``` cpp
|
| 614 |
template<class charT, class traits>
|
| 615 |
-
void swap(basic_ifstream<charT, traits>& x,
|
| 616 |
-
basic_ifstream<charT, traits>& y);
|
| 617 |
```
|
| 618 |
|
| 619 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 620 |
|
| 621 |
#### Member functions <a id="ifstream.members">[[ifstream.members]]</a>
|
|
@@ -658,10 +683,12 @@ void close();
|
|
| 658 |
pointer, calls `setstate(failbit)` (which may throw
|
| 659 |
`ios_base::failure`) [[iostate.flags]].
|
| 660 |
|
| 661 |
### Class template `basic_ofstream` <a id="ofstream">[[ofstream]]</a>
|
| 662 |
|
|
|
|
|
|
|
| 663 |
``` cpp
|
| 664 |
namespace std {
|
| 665 |
template<class charT, class traits = char_traits<charT>>
|
| 666 |
class basic_ofstream : public basic_ostream<charT, traits> {
|
| 667 |
public:
|
|
@@ -677,18 +704,19 @@ namespace std {
|
|
| 677 |
ios_base::openmode mode = ios_base::out);
|
| 678 |
explicit basic_ofstream(const filesystem::path::value_type* s, // wide systems only; see [fstream.syn]
|
| 679 |
ios_base::openmode mode = ios_base::out);
|
| 680 |
explicit basic_ofstream(const string& s,
|
| 681 |
ios_base::openmode mode = ios_base::out);
|
| 682 |
-
|
| 683 |
-
|
| 684 |
basic_ofstream(const basic_ofstream&) = delete;
|
| 685 |
basic_ofstream(basic_ofstream&& rhs);
|
| 686 |
|
| 687 |
-
// [ofstream.assign], assign and swap
|
| 688 |
basic_ofstream& operator=(const basic_ofstream&) = delete;
|
| 689 |
basic_ofstream& operator=(basic_ofstream&& rhs);
|
|
|
|
|
|
|
| 690 |
void swap(basic_ofstream& rhs);
|
| 691 |
|
| 692 |
// [ofstream.members], members
|
| 693 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 694 |
|
|
@@ -697,17 +725,14 @@ namespace std {
|
|
| 697 |
void open(const filesystem::path::value_type* s,
|
| 698 |
ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
|
| 699 |
void open(const string& s, ios_base::openmode mode = ios_base::out);
|
| 700 |
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
|
| 701 |
void close();
|
|
|
|
| 702 |
private:
|
| 703 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 704 |
};
|
| 705 |
-
|
| 706 |
-
template<class charT, class traits>
|
| 707 |
-
void swap(basic_ofstream<charT, traits>& x,
|
| 708 |
-
basic_ofstream<charT, traits>& y);
|
| 709 |
}
|
| 710 |
```
|
| 711 |
|
| 712 |
The class `basic_ofstream<charT, traits>` supports writing to named
|
| 713 |
files. It uses a `basic_filebuf<{}charT, traits>` object to control the
|
|
@@ -740,38 +765,44 @@ with `basic_filebuf<charT, traits>()` [[filebuf.cons]], then calls
|
|
| 740 |
null pointer, calls `setstate(failbit)`.
|
| 741 |
|
| 742 |
``` cpp
|
| 743 |
explicit basic_ofstream(const string& s,
|
| 744 |
ios_base::openmode mode = ios_base::out);
|
| 745 |
-
explicit basic_ofstream(const filesystem::path& s,
|
| 746 |
-
ios_base::openmode mode = ios_base::out);
|
| 747 |
```
|
| 748 |
|
| 749 |
*Effects:* Equivalent to: `basic_ofstream(s.c_str(), mode)`.
|
| 750 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 751 |
``` cpp
|
| 752 |
basic_ofstream(basic_ofstream&& rhs);
|
| 753 |
```
|
| 754 |
|
| 755 |
*Effects:* Move constructs the base class, and the contained
|
| 756 |
`basic_filebuf`. Then calls
|
| 757 |
`basic_ostream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 758 |
contained `basic_filebuf`.
|
| 759 |
|
| 760 |
-
####
|
| 761 |
|
| 762 |
``` cpp
|
| 763 |
void swap(basic_ofstream& rhs);
|
| 764 |
```
|
| 765 |
|
| 766 |
*Effects:* Exchanges the state of `*this` and `rhs` by calling
|
| 767 |
`basic_ostream<charT, traits>::swap(rhs)` and `sb.swap(rhs.sb)`.
|
| 768 |
|
| 769 |
``` cpp
|
| 770 |
template<class charT, class traits>
|
| 771 |
-
void swap(basic_ofstream<charT, traits>& x,
|
| 772 |
-
basic_ofstream<charT, traits>& y);
|
| 773 |
```
|
| 774 |
|
| 775 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 776 |
|
| 777 |
#### Member functions <a id="ofstream.members">[[ofstream.members]]</a>
|
|
@@ -814,10 +845,12 @@ void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
|
|
| 814 |
|
| 815 |
*Effects:* Calls `open(s.c_str(), mode)`.
|
| 816 |
|
| 817 |
### Class template `basic_fstream` <a id="fstream">[[fstream]]</a>
|
| 818 |
|
|
|
|
|
|
|
| 819 |
``` cpp
|
| 820 |
namespace std {
|
| 821 |
template<class charT, class traits = char_traits<charT>>
|
| 822 |
class basic_fstream : public basic_iostream<charT, traits> {
|
| 823 |
public:
|
|
@@ -836,19 +869,19 @@ namespace std {
|
|
| 836 |
const filesystem::path::value_type* s,
|
| 837 |
ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
|
| 838 |
explicit basic_fstream(
|
| 839 |
const string& s,
|
| 840 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 841 |
-
|
| 842 |
-
const
|
| 843 |
-
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 844 |
basic_fstream(const basic_fstream&) = delete;
|
| 845 |
basic_fstream(basic_fstream&& rhs);
|
| 846 |
|
| 847 |
-
// [fstream.assign], assign and swap
|
| 848 |
basic_fstream& operator=(const basic_fstream&) = delete;
|
| 849 |
basic_fstream& operator=(basic_fstream&& rhs);
|
|
|
|
|
|
|
| 850 |
void swap(basic_fstream& rhs);
|
| 851 |
|
| 852 |
// [fstream.members], members
|
| 853 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 854 |
bool is_open() const;
|
|
@@ -867,14 +900,10 @@ namespace std {
|
|
| 867 |
void close();
|
| 868 |
|
| 869 |
private:
|
| 870 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 871 |
};
|
| 872 |
-
|
| 873 |
-
template<class charT, class traits>
|
| 874 |
-
void swap(basic_fstream<charT, traits>& x,
|
| 875 |
-
basic_fstream<charT, traits>& y);
|
| 876 |
}
|
| 877 |
```
|
| 878 |
|
| 879 |
The class template `basic_fstream<charT, traits>` supports reading and
|
| 880 |
writing from named files. It uses a `basic_filebuf<charT, traits>`
|
|
@@ -910,27 +939,33 @@ explicit basic_fstream(
|
|
| 910 |
|
| 911 |
``` cpp
|
| 912 |
explicit basic_fstream(
|
| 913 |
const string& s,
|
| 914 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 915 |
-
explicit basic_fstream(
|
| 916 |
-
const filesystem::path& s,
|
| 917 |
-
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 918 |
```
|
| 919 |
|
| 920 |
*Effects:* Equivalent to: `basic_fstream(s.c_str(), mode)`.
|
| 921 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
``` cpp
|
| 923 |
basic_fstream(basic_fstream&& rhs);
|
| 924 |
```
|
| 925 |
|
| 926 |
*Effects:* Move constructs the base class, and the contained
|
| 927 |
`basic_filebuf`. Then calls
|
| 928 |
`basic_istream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 929 |
contained `basic_filebuf`.
|
| 930 |
|
| 931 |
-
####
|
| 932 |
|
| 933 |
``` cpp
|
| 934 |
void swap(basic_fstream& rhs);
|
| 935 |
```
|
| 936 |
|
|
|
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
namespace std {
|
| 7 |
template<class charT, class traits = char_traits<charT>>
|
| 8 |
class basic_filebuf;
|
| 9 |
+
|
| 10 |
+
template<class charT, class traits>
|
| 11 |
+
void swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
|
| 12 |
+
|
| 13 |
using filebuf = basic_filebuf<char>;
|
| 14 |
using wfilebuf = basic_filebuf<wchar_t>;
|
| 15 |
|
| 16 |
template<class charT, class traits = char_traits<charT>>
|
| 17 |
class basic_ifstream;
|
| 18 |
+
|
| 19 |
+
template<class charT, class traits>
|
| 20 |
+
void swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y);
|
| 21 |
+
|
| 22 |
using ifstream = basic_ifstream<char>;
|
| 23 |
using wifstream = basic_ifstream<wchar_t>;
|
| 24 |
|
| 25 |
template<class charT, class traits = char_traits<charT>>
|
| 26 |
class basic_ofstream;
|
| 27 |
+
|
| 28 |
+
template<class charT, class traits>
|
| 29 |
+
void swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y);
|
| 30 |
+
|
| 31 |
using ofstream = basic_ofstream<char>;
|
| 32 |
using wofstream = basic_ofstream<wchar_t>;
|
| 33 |
|
| 34 |
template<class charT, class traits = char_traits<charT>>
|
| 35 |
class basic_fstream;
|
| 36 |
+
|
| 37 |
+
template<class charT, class traits>
|
| 38 |
+
void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y);
|
| 39 |
+
|
| 40 |
using fstream = basic_fstream<char>;
|
| 41 |
using wfstream = basic_fstream<wchar_t>;
|
| 42 |
}
|
| 43 |
```
|
| 44 |
|
|
|
|
| 51 |
file typically holds multibyte character sequences and the
|
| 52 |
`basic_filebuf` object converts those multibyte sequences into wide
|
| 53 |
character sequences. — *end note*]
|
| 54 |
|
| 55 |
In subclause [[file.streams]], member functions taking arguments of
|
| 56 |
+
`const filesystem::path::value_type*` are only provided on systems where
|
| 57 |
+
`filesystem::path::value_type` [[fs.class.path]] is not `char`.
|
| 58 |
|
| 59 |
[*Note 2*: These functions enable class `path` support for systems with
|
| 60 |
a wide native path character type, such as `wchar_t`. — *end note*]
|
| 61 |
|
| 62 |
### Class template `basic_filebuf` <a id="filebuf">[[filebuf]]</a>
|
| 63 |
|
| 64 |
+
#### General <a id="filebuf.general">[[filebuf.general]]</a>
|
| 65 |
+
|
| 66 |
``` cpp
|
| 67 |
namespace std {
|
| 68 |
template<class charT, class traits = char_traits<charT>>
|
| 69 |
class basic_filebuf : public basic_streambuf<charT, traits> {
|
| 70 |
public:
|
|
|
|
| 78 |
basic_filebuf();
|
| 79 |
basic_filebuf(const basic_filebuf&) = delete;
|
| 80 |
basic_filebuf(basic_filebuf&& rhs);
|
| 81 |
virtual ~basic_filebuf();
|
| 82 |
|
| 83 |
+
// [filebuf.assign], assignment and swap
|
| 84 |
basic_filebuf& operator=(const basic_filebuf&) = delete;
|
| 85 |
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 86 |
void swap(basic_filebuf& rhs);
|
| 87 |
|
| 88 |
// [filebuf.members], members
|
|
|
|
| 113 |
ios_base::openmode which
|
| 114 |
= ios_base::in | ios_base::out) override;
|
| 115 |
int sync() override;
|
| 116 |
void imbue(const locale& loc) override;
|
| 117 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
}
|
| 119 |
```
|
| 120 |
|
| 121 |
The class `basic_filebuf<charT, traits>` associates both the input
|
| 122 |
sequence and the output sequence with a file.
|
|
|
|
| 214 |
|
| 215 |
*Effects:* Exchanges the state of `*this` and `rhs`.
|
| 216 |
|
| 217 |
``` cpp
|
| 218 |
template<class charT, class traits>
|
| 219 |
+
void swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
|
|
|
|
| 220 |
```
|
| 221 |
|
| 222 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 223 |
|
| 224 |
#### Member functions <a id="filebuf.members">[[filebuf.members]]</a>
|
|
|
|
| 245 |
[[filebuf.open.modes]]. If `mode` is not some combination of flags shown
|
| 246 |
in the table then the open fails.
|
| 247 |
|
| 248 |
**Table: File open modes** <a id="filebuf.open.modes">[filebuf.open.modes]</a>
|
| 249 |
|
| 250 |
+
| `binary` | `in` | `out` | `trunc` | `app` | `noreplace` | `stdio` equivalent |
|
| 251 |
+
| -------- | ---- | ----- | ------- | ----- | ----------- | ------------------ |
|
| 252 |
+
| | | + | | | | `"w"` |
|
| 253 |
+
| | | + | | | + | `"wx"` |
|
| 254 |
+
| | | + | + | | | `"w"` |
|
| 255 |
+
| | | + | + | | + | `"wx"` |
|
| 256 |
+
| | | + | | + | | `"a"` |
|
| 257 |
+
| | | | | + | | `"a"` |
|
| 258 |
+
| | + | | | | | `"r"` |
|
| 259 |
+
| | + | + | | | | `"r+"` |
|
| 260 |
+
| | + | + | + | | | `"w+"` |
|
| 261 |
+
| | + | + | + | | + | `"w+x"` |
|
| 262 |
+
| | + | + | | + | | `"a+"` |
|
| 263 |
+
| | + | | | + | | `"a+"` |
|
| 264 |
+
| + | | + | | | | `"wb"` |
|
| 265 |
+
| + | | + | | | + | `"wbx"` |
|
| 266 |
+
| + | | + | + | | | `"wb"` |
|
| 267 |
+
| + | | + | + | | + | `"wbx"` |
|
| 268 |
+
| + | | + | | + | | `"ab"` |
|
| 269 |
+
| + | | | | + | | `"ab"` |
|
| 270 |
+
| + | + | | | | | `"rb"` |
|
| 271 |
+
| + | + | + | | | | `"r+b"` |
|
| 272 |
+
| + | + | + | + | | | `"w+b"` |
|
| 273 |
+
| + | + | + | + | | + | `"w+bx"` |
|
| 274 |
+
| + | + | + | | + | | `"a+b"` |
|
| 275 |
+
| + | + | | | + | | `"a+b"` |
|
| 276 |
|
| 277 |
|
| 278 |
If the open operation succeeds and `ios_base::ate` is set in `mode`,
|
| 279 |
positions the file to the end (as if by calling
|
| 280 |
`fseek(file, 0, SEEK_END)`, where `file` is the pointer returned by
|
| 281 |
+
calling `fopen`).[^38]
|
| 282 |
|
| 283 |
If the repositioning operation fails, calls `close()` and returns a null
|
| 284 |
pointer to indicate failure.
|
| 285 |
|
| 286 |
*Returns:* `this` if successful, a null pointer otherwise.
|
|
|
|
| 307 |
`fclose(file)`). If any of the calls made by the function, including
|
| 308 |
`fclose`, fails, `close` fails by returning a null pointer. If one of
|
| 309 |
these calls throws an exception, the exception is caught and rethrown
|
| 310 |
after closing the file.
|
| 311 |
|
| 312 |
+
*Ensures:* `is_open() == false`.
|
| 313 |
+
|
| 314 |
*Returns:* `this` on success, a null pointer otherwise.
|
| 315 |
|
|
|
|
|
|
|
| 316 |
#### Overridden virtual functions <a id="filebuf.virtuals">[[filebuf.virtuals]]</a>
|
| 317 |
|
| 318 |
``` cpp
|
| 319 |
streamsize showmanyc() override;
|
| 320 |
```
|
| 321 |
|
| 322 |
*Effects:* Behaves the same as `basic_streambuf::showmanyc()`
|
| 323 |
[[streambuf.virtuals]].
|
| 324 |
|
| 325 |
+
*Remarks:* An implementation may provide an overriding definition for
|
| 326 |
+
this function signature if it can determine whether more characters can
|
| 327 |
be read from the input sequence.
|
| 328 |
|
| 329 |
``` cpp
|
| 330 |
int_type underflow() override;
|
| 331 |
```
|
|
|
|
| 447 |
and if the last operation was output, then update the output sequence
|
| 448 |
and write any unshift sequence. Next, seek to the new position: if
|
| 449 |
`width > 0`, call `fseek(file, width * off, whence)`, otherwise call
|
| 450 |
`fseek(file, 0, whence)`.
|
| 451 |
|
| 452 |
+
*Returns:* A newly constructed `pos_type` object that stores the
|
| 453 |
+
resultant stream position, if possible. If the positioning operation
|
| 454 |
+
fails, or if the object cannot represent the resultant stream position,
|
| 455 |
+
returns `pos_type(off_type(-1))`.
|
| 456 |
+
|
| 457 |
*Remarks:* “The last operation was output” means either the last virtual
|
| 458 |
operation was overflow or the put buffer is non-empty. “Write any
|
| 459 |
unshift sequence” means, if `width` if less than zero then call
|
| 460 |
`a_codecvt.unshift(state, xbuf, xbuf+XSIZE, xbuf_end)` and output the
|
| 461 |
resulting unshift sequence. The function determines one of three values
|
|
|
|
| 468 |
| ---------------- | ------------------ |
|
| 469 |
| `basic_ios::beg` | `SEEK_SET` |
|
| 470 |
| `basic_ios::cur` | `SEEK_CUR` |
|
| 471 |
| `basic_ios::end` | `SEEK_END` |
|
| 472 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
``` cpp
|
| 474 |
pos_type seekpos(pos_type sp,
|
| 475 |
ios_base::openmode which
|
| 476 |
= ios_base::in | ios_base::out) override;
|
| 477 |
```
|
|
|
|
| 521 |
characters. This in turn may require the implementation to be able to
|
| 522 |
reconstruct the original contents of the file.
|
| 523 |
|
| 524 |
### Class template `basic_ifstream` <a id="ifstream">[[ifstream]]</a>
|
| 525 |
|
| 526 |
+
#### General <a id="ifstream.general">[[ifstream.general]]</a>
|
| 527 |
+
|
| 528 |
``` cpp
|
| 529 |
namespace std {
|
| 530 |
template<class charT, class traits = char_traits<charT>>
|
| 531 |
class basic_ifstream : public basic_istream<charT, traits> {
|
| 532 |
public:
|
|
|
|
| 542 |
ios_base::openmode mode = ios_base::in);
|
| 543 |
explicit basic_ifstream(const filesystem::path::value_type* s,
|
| 544 |
ios_base::openmode mode = ios_base::in);// wide systems only; see [fstream.syn]
|
| 545 |
explicit basic_ifstream(const string& s,
|
| 546 |
ios_base::openmode mode = ios_base::in);
|
| 547 |
+
template<class T>
|
| 548 |
+
explicit basic_ifstream(const T& s, ios_base::openmode mode = ios_base::in);
|
| 549 |
basic_ifstream(const basic_ifstream&) = delete;
|
| 550 |
basic_ifstream(basic_ifstream&& rhs);
|
| 551 |
|
|
|
|
| 552 |
basic_ifstream& operator=(const basic_ifstream&) = delete;
|
| 553 |
basic_ifstream& operator=(basic_ifstream&& rhs);
|
| 554 |
+
|
| 555 |
+
// [ifstream.swap], swap
|
| 556 |
void swap(basic_ifstream& rhs);
|
| 557 |
|
| 558 |
// [ifstream.members], members
|
| 559 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 560 |
|
|
|
|
| 563 |
void open(const filesystem::path::value_type* s,
|
| 564 |
ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
|
| 565 |
void open(const string& s, ios_base::openmode mode = ios_base::in);
|
| 566 |
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);
|
| 567 |
void close();
|
| 568 |
+
|
| 569 |
private:
|
| 570 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 571 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
}
|
| 573 |
```
|
| 574 |
|
| 575 |
The class `basic_ifstream<charT, traits>` supports reading from named
|
| 576 |
files. It uses a `basic_filebuf<{}charT, traits>` object to control the
|
|
|
|
| 603 |
pointer, calls `setstate(failbit)`.
|
| 604 |
|
| 605 |
``` cpp
|
| 606 |
explicit basic_ifstream(const string& s,
|
| 607 |
ios_base::openmode mode = ios_base::in);
|
|
|
|
|
|
|
| 608 |
```
|
| 609 |
|
| 610 |
*Effects:* Equivalent to: `basic_ifstream(s.c_str(), mode)`.
|
| 611 |
|
| 612 |
+
``` cpp
|
| 613 |
+
template<class T>
|
| 614 |
+
explicit basic_ifstream(const T& s, ios_base::openmode mode = ios_base::in);
|
| 615 |
+
```
|
| 616 |
+
|
| 617 |
+
*Constraints:* `is_same_v<T, filesystem::path>` is `true`.
|
| 618 |
+
|
| 619 |
+
*Effects:* Equivalent to: `basic_ifstream(s.c_str(), mode)`.
|
| 620 |
+
|
| 621 |
``` cpp
|
| 622 |
basic_ifstream(basic_ifstream&& rhs);
|
| 623 |
```
|
| 624 |
|
| 625 |
*Effects:* Move constructs the base class, and the contained
|
| 626 |
`basic_filebuf`. Then calls
|
| 627 |
`basic_istream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 628 |
contained `basic_filebuf`.
|
| 629 |
|
| 630 |
+
#### Swap <a id="ifstream.swap">[[ifstream.swap]]</a>
|
| 631 |
|
| 632 |
``` cpp
|
| 633 |
void swap(basic_ifstream& rhs);
|
| 634 |
```
|
| 635 |
|
| 636 |
*Effects:* Exchanges the state of `*this` and `rhs` by calling
|
| 637 |
`basic_istream<charT, traits>::swap(rhs)` and `sb.swap(rhs.sb)`.
|
| 638 |
|
| 639 |
``` cpp
|
| 640 |
template<class charT, class traits>
|
| 641 |
+
void swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y);
|
|
|
|
| 642 |
```
|
| 643 |
|
| 644 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 645 |
|
| 646 |
#### Member functions <a id="ifstream.members">[[ifstream.members]]</a>
|
|
|
|
| 683 |
pointer, calls `setstate(failbit)` (which may throw
|
| 684 |
`ios_base::failure`) [[iostate.flags]].
|
| 685 |
|
| 686 |
### Class template `basic_ofstream` <a id="ofstream">[[ofstream]]</a>
|
| 687 |
|
| 688 |
+
#### General <a id="ofstream.general">[[ofstream.general]]</a>
|
| 689 |
+
|
| 690 |
``` cpp
|
| 691 |
namespace std {
|
| 692 |
template<class charT, class traits = char_traits<charT>>
|
| 693 |
class basic_ofstream : public basic_ostream<charT, traits> {
|
| 694 |
public:
|
|
|
|
| 704 |
ios_base::openmode mode = ios_base::out);
|
| 705 |
explicit basic_ofstream(const filesystem::path::value_type* s, // wide systems only; see [fstream.syn]
|
| 706 |
ios_base::openmode mode = ios_base::out);
|
| 707 |
explicit basic_ofstream(const string& s,
|
| 708 |
ios_base::openmode mode = ios_base::out);
|
| 709 |
+
template<class T>
|
| 710 |
+
explicit basic_ofstream(const T& s, ios_base::openmode mode = ios_base::out);
|
| 711 |
basic_ofstream(const basic_ofstream&) = delete;
|
| 712 |
basic_ofstream(basic_ofstream&& rhs);
|
| 713 |
|
|
|
|
| 714 |
basic_ofstream& operator=(const basic_ofstream&) = delete;
|
| 715 |
basic_ofstream& operator=(basic_ofstream&& rhs);
|
| 716 |
+
|
| 717 |
+
// [ofstream.swap], swap
|
| 718 |
void swap(basic_ofstream& rhs);
|
| 719 |
|
| 720 |
// [ofstream.members], members
|
| 721 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 722 |
|
|
|
|
| 725 |
void open(const filesystem::path::value_type* s,
|
| 726 |
ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
|
| 727 |
void open(const string& s, ios_base::openmode mode = ios_base::out);
|
| 728 |
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
|
| 729 |
void close();
|
| 730 |
+
|
| 731 |
private:
|
| 732 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 733 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 734 |
}
|
| 735 |
```
|
| 736 |
|
| 737 |
The class `basic_ofstream<charT, traits>` supports writing to named
|
| 738 |
files. It uses a `basic_filebuf<{}charT, traits>` object to control the
|
|
|
|
| 765 |
null pointer, calls `setstate(failbit)`.
|
| 766 |
|
| 767 |
``` cpp
|
| 768 |
explicit basic_ofstream(const string& s,
|
| 769 |
ios_base::openmode mode = ios_base::out);
|
|
|
|
|
|
|
| 770 |
```
|
| 771 |
|
| 772 |
*Effects:* Equivalent to: `basic_ofstream(s.c_str(), mode)`.
|
| 773 |
|
| 774 |
+
``` cpp
|
| 775 |
+
template<class T>
|
| 776 |
+
explicit basic_ofstream(const T& s, ios_base::openmode mode = ios_base::out);
|
| 777 |
+
```
|
| 778 |
+
|
| 779 |
+
*Constraints:* `is_same_v<T, filesystem::path>` is `true`.
|
| 780 |
+
|
| 781 |
+
*Effects:* Equivalent to: `basic_ofstream(s.c_str(), mode)`.
|
| 782 |
+
|
| 783 |
``` cpp
|
| 784 |
basic_ofstream(basic_ofstream&& rhs);
|
| 785 |
```
|
| 786 |
|
| 787 |
*Effects:* Move constructs the base class, and the contained
|
| 788 |
`basic_filebuf`. Then calls
|
| 789 |
`basic_ostream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 790 |
contained `basic_filebuf`.
|
| 791 |
|
| 792 |
+
#### Swap <a id="ofstream.swap">[[ofstream.swap]]</a>
|
| 793 |
|
| 794 |
``` cpp
|
| 795 |
void swap(basic_ofstream& rhs);
|
| 796 |
```
|
| 797 |
|
| 798 |
*Effects:* Exchanges the state of `*this` and `rhs` by calling
|
| 799 |
`basic_ostream<charT, traits>::swap(rhs)` and `sb.swap(rhs.sb)`.
|
| 800 |
|
| 801 |
``` cpp
|
| 802 |
template<class charT, class traits>
|
| 803 |
+
void swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y);
|
|
|
|
| 804 |
```
|
| 805 |
|
| 806 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 807 |
|
| 808 |
#### Member functions <a id="ofstream.members">[[ofstream.members]]</a>
|
|
|
|
| 845 |
|
| 846 |
*Effects:* Calls `open(s.c_str(), mode)`.
|
| 847 |
|
| 848 |
### Class template `basic_fstream` <a id="fstream">[[fstream]]</a>
|
| 849 |
|
| 850 |
+
#### General <a id="fstream.general">[[fstream.general]]</a>
|
| 851 |
+
|
| 852 |
``` cpp
|
| 853 |
namespace std {
|
| 854 |
template<class charT, class traits = char_traits<charT>>
|
| 855 |
class basic_fstream : public basic_iostream<charT, traits> {
|
| 856 |
public:
|
|
|
|
| 869 |
const filesystem::path::value_type* s,
|
| 870 |
ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
|
| 871 |
explicit basic_fstream(
|
| 872 |
const string& s,
|
| 873 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 874 |
+
template<class T>
|
| 875 |
+
explicit basic_fstream(const T& s, ios_base::openmode mode = ios_base::in | ios_base::out);
|
|
|
|
| 876 |
basic_fstream(const basic_fstream&) = delete;
|
| 877 |
basic_fstream(basic_fstream&& rhs);
|
| 878 |
|
|
|
|
| 879 |
basic_fstream& operator=(const basic_fstream&) = delete;
|
| 880 |
basic_fstream& operator=(basic_fstream&& rhs);
|
| 881 |
+
|
| 882 |
+
// [fstream.swap], swap
|
| 883 |
void swap(basic_fstream& rhs);
|
| 884 |
|
| 885 |
// [fstream.members], members
|
| 886 |
basic_filebuf<charT, traits>* rdbuf() const;
|
| 887 |
bool is_open() const;
|
|
|
|
| 900 |
void close();
|
| 901 |
|
| 902 |
private:
|
| 903 |
basic_filebuf<charT, traits> sb; // exposition only
|
| 904 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 905 |
}
|
| 906 |
```
|
| 907 |
|
| 908 |
The class template `basic_fstream<charT, traits>` supports reading and
|
| 909 |
writing from named files. It uses a `basic_filebuf<charT, traits>`
|
|
|
|
| 939 |
|
| 940 |
``` cpp
|
| 941 |
explicit basic_fstream(
|
| 942 |
const string& s,
|
| 943 |
ios_base::openmode mode = ios_base::in | ios_base::out);
|
|
|
|
|
|
|
|
|
|
| 944 |
```
|
| 945 |
|
| 946 |
*Effects:* Equivalent to: `basic_fstream(s.c_str(), mode)`.
|
| 947 |
|
| 948 |
+
``` cpp
|
| 949 |
+
template<class T>
|
| 950 |
+
explicit basic_fstream(const T& s, ios_base::openmode mode = ios_base::in | ios_base::out);
|
| 951 |
+
```
|
| 952 |
+
|
| 953 |
+
*Constraints:* `is_same_v<T, filesystem::path>` is `true`.
|
| 954 |
+
|
| 955 |
+
*Effects:* Equivalent to: `basic_fstream(s.c_str(), mode)`.
|
| 956 |
+
|
| 957 |
``` cpp
|
| 958 |
basic_fstream(basic_fstream&& rhs);
|
| 959 |
```
|
| 960 |
|
| 961 |
*Effects:* Move constructs the base class, and the contained
|
| 962 |
`basic_filebuf`. Then calls
|
| 963 |
`basic_istream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 964 |
contained `basic_filebuf`.
|
| 965 |
|
| 966 |
+
#### Swap <a id="fstream.swap">[[fstream.swap]]</a>
|
| 967 |
|
| 968 |
``` cpp
|
| 969 |
void swap(basic_fstream& rhs);
|
| 970 |
```
|
| 971 |
|