libstdc++
fstream
Go to the documentation of this file.
1// File based streams -*- C++ -*-
2
3// Copyright (C) 1997-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file include/fstream
26 * This is a Standard C++ Library header.
27 */
28
29//
30// ISO C++ 14882: 27.8 File-based streams
31//
32
33#ifndef _GLIBCXX_FSTREAM
34#define _GLIBCXX_FSTREAM 1
35
36#ifdef _GLIBCXX_SYSHDR
37#pragma GCC system_header
38#endif
39
40#include <bits/requires_hosted.h> // iostreams
41
42#include <istream>
43#include <ostream>
44#include <bits/iosfwd_file.h>
45#include <bits/codecvt.h>
46#include <cstdio> // For BUFSIZ
47#include <bits/basic_file.h> // For __basic_file, __c_lock
48#if __cplusplus >= 201103L
49#include <string> // For std::string overloads.
50#endif
51
52#define __glibcxx_want_fstream_native_handle
53#include <bits/version.h>
54
55// This can be overridden by the target's os_defines.h
56#ifndef _GLIBCXX_BUFSIZ
57# define _GLIBCXX_BUFSIZ BUFSIZ
58#endif
59
60namespace std _GLIBCXX_VISIBILITY(default)
61{
62_GLIBCXX_BEGIN_NAMESPACE_VERSION
63
64#if __cplusplus >= 201703L
65 // Enable if _Path is a filesystem::path or experimental::filesystem::path
66 template<typename _Path, typename _Result = _Path, typename _Path2
67 = decltype(std::declval<_Path&>().make_preferred().filename())>
68 using _If_fs_path = enable_if_t<is_same_v<_Path, _Path2>, _Result>;
69#endif // C++17
70
71
72 // [27.8.1.1] template class basic_filebuf
73 /**
74 * @brief The actual work of input and output (for files).
75 * @ingroup io
76 *
77 * @tparam _CharT Type of character stream.
78 * @tparam _Traits Traits for character type, defaults to
79 * char_traits<_CharT>.
80 *
81 * This class associates both its input and output sequence with an
82 * external disk file, and maintains a joint file position for both
83 * sequences. Many of its semantics are described in terms of similar
84 * behavior in the Standard C Library's @c FILE streams.
85 *
86 * Requirements on traits_type, specific to this class:
87 * - traits_type::pos_type must be fpos<traits_type::state_type>
88 * - traits_type::off_type must be streamoff
89 * - traits_type::state_type must be Assignable and DefaultConstructible,
90 * - traits_type::state_type() must be the initial state for codecvt.
91 */
92 template<typename _CharT, typename _Traits>
93 class basic_filebuf : public basic_streambuf<_CharT, _Traits>
94 {
95#if __cplusplus >= 201103L
96 template<typename _Tp>
97 using __chk_state = __and_<is_copy_assignable<_Tp>,
100
101 static_assert(__chk_state<typename _Traits::state_type>::value,
102 "state_type must be CopyAssignable, CopyConstructible"
103 " and DefaultConstructible");
104
105 static_assert(is_same<typename _Traits::pos_type,
107 "pos_type must be fpos<state_type>");
108#endif
109 public:
110 // Types:
111 typedef _CharT char_type;
112 typedef _Traits traits_type;
113 typedef typename traits_type::int_type int_type;
114 typedef typename traits_type::pos_type pos_type;
115 typedef typename traits_type::off_type off_type;
116
117 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
118 typedef basic_filebuf<char_type, traits_type> __filebuf_type;
119 typedef __basic_file<char> __file_type;
120 typedef typename traits_type::state_type __state_type;
121 typedef codecvt<char_type, char, __state_type> __codecvt_type;
122
123 friend class ios_base; // For sync_with_stdio.
124
125 protected:
126 // Data Members:
127 // MT lock inherited from libio or other low-level io library.
128 __c_lock _M_lock;
129
130 // External buffer.
131 __file_type _M_file;
132
133 /// Place to stash in || out || in | out settings for current filebuf.
135
136 // Beginning state type for codecvt.
137 __state_type _M_state_beg;
138
139 // During output, the state that corresponds to pptr(),
140 // during input, the state that corresponds to egptr() and
141 // _M_ext_next.
142 __state_type _M_state_cur;
143
144 // Not used for output. During input, the state that corresponds
145 // to eback() and _M_ext_buf.
146 __state_type _M_state_last;
147
148 /// Pointer to the beginning of internal buffer.
149 char_type* _M_buf;
150
151 /**
152 * Actual size of internal buffer. This number is equal to the size
153 * of the put area + 1 position, reserved for the overflow char of
154 * a full area.
155 */
157
158 // Set iff _M_buf is allocated memory from _M_allocate_internal_buffer.
159 bool _M_buf_allocated;
160
161 /**
162 * _M_reading == false && _M_writing == false for @b uncommitted mode;
163 * _M_reading == true for @b read mode;
164 * _M_writing == true for @b write mode;
165 *
166 * NB: _M_reading == true && _M_writing == true is unused.
167 */
169 bool _M_writing;
170
171 ///@{
172 /**
173 * Necessary bits for putback buffer management.
174 *
175 * @note pbacks of over one character are not currently supported.
176 */
177 char_type _M_pback;
181 ///@}
182
183 // Cached codecvt facet.
184 const __codecvt_type* _M_codecvt;
185
186 /**
187 * Buffer for external characters. Used for input when
188 * codecvt::always_noconv() == false. When valid, this corresponds
189 * to eback().
190 */
192
193 /**
194 * Size of buffer held by _M_ext_buf.
195 */
197
198 /**
199 * Pointers into the buffer held by _M_ext_buf that delimit a
200 * subsequence of bytes that have been read but not yet converted.
201 * When valid, _M_ext_next corresponds to egptr().
202 */
203 const char* _M_ext_next;
204 char* _M_ext_end;
205
206 /**
207 * Initializes pback buffers, and moves normal buffers to safety.
208 * Assumptions:
209 * _M_in_cur has already been moved back
210 */
211 void
213 {
214 if (!_M_pback_init)
215 {
216 _M_pback_cur_save = this->gptr();
217 _M_pback_end_save = this->egptr();
218 this->setg(&_M_pback, &_M_pback, &_M_pback + 1);
219 _M_pback_init = true;
220 }
221 }
222
223 /**
224 * Deactivates pback buffer contents, and restores normal buffer.
225 * Assumptions:
226 * The pback buffer has only moved forward.
227 */
228 void
230 {
231 if (_M_pback_init)
232 {
233 // Length _M_in_cur moved in the pback buffer.
234 _M_pback_cur_save += this->gptr() != this->eback();
236 _M_pback_init = false;
237 }
238 }
239
240 public:
241 // Constructors/destructor:
242 /**
243 * @brief Does not open any files.
244 *
245 * The default constructor initializes the parent class using its
246 * own default ctor.
247 */
249
250#if __cplusplus >= 201103L
251 basic_filebuf(const basic_filebuf&) = delete;
253#endif
254
255 /**
256 * @brief The destructor closes the file first.
257 */
258 virtual
260 {
261 __try
262 { this->close(); }
263 __catch(...)
264 { }
265 }
266
267#if __cplusplus >= 201103L
268 basic_filebuf& operator=(const basic_filebuf&) = delete;
269 basic_filebuf& operator=(basic_filebuf&&);
270 void swap(basic_filebuf&);
271#endif
272
273 // Members:
274 /**
275 * @brief Returns true if the external file is open.
276 */
277 _GLIBCXX_NODISCARD
278 bool
279 is_open() const throw()
280 { return _M_file.is_open(); }
281
282 /**
283 * @brief Opens an external file.
284 * @param __s The name of the file.
285 * @param __mode The open mode flags.
286 * @return @c this on success, NULL on failure
287 *
288 * If a file is already open, this function immediately fails.
289 * Otherwise it tries to open the file named @a __s using the flags
290 * given in @a __mode.
291 *
292 * Table 92, adapted here, gives the relation between openmode
293 * combinations and the equivalent @c fopen() flags.
294 * (NB: lines app, in|out|app, in|app, binary|app, binary|in|out|app,
295 * and binary|in|app per DR 596)
296 * <pre>
297 * +---------------------------------------------------------+
298 * | ios_base Flag combination stdio equivalent |
299 * |binary in out trunc app |
300 * +---------------------------------------------------------+
301 * | + w |
302 * | + + a |
303 * | + a |
304 * | + + w |
305 * | + r |
306 * | + + r+ |
307 * | + + + w+ |
308 * | + + + a+ |
309 * | + + a+ |
310 * +---------------------------------------------------------+
311 * | + + wb |
312 * | + + + ab |
313 * | + + ab |
314 * | + + + wb |
315 * | + + rb |
316 * | + + + r+b |
317 * | + + + + w+b |
318 * | + + + + a+b |
319 * | + + + a+b |
320 * +---------------------------------------------------------+
321 * </pre>
322 */
323 __filebuf_type*
324 open(const char* __s, ios_base::openmode __mode);
325
326#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
327 /**
328 * @brief Opens an external file.
329 * @param __s The name of the file, as a wide character string.
330 * @param __mode The open mode flags.
331 * @return @c this on success, NULL on failure
332 */
333 __filebuf_type*
334 open(const wchar_t* __s, ios_base::openmode __mode);
335#endif
336
337#if __cplusplus >= 201103L
338 /**
339 * @brief Opens an external file.
340 * @param __s The name of the file.
341 * @param __mode The open mode flags.
342 * @return @c this on success, NULL on failure
343 */
344 __filebuf_type*
346 { return open(__s.c_str(), __mode); }
347
348#if __cplusplus >= 201703L
349 /**
350 * @brief Opens an external file.
351 * @param __s The name of the file, as a filesystem::path.
352 * @param __mode The open mode flags.
353 * @return @c this on success, NULL on failure
354 */
355 template<typename _Path>
356 _If_fs_path<_Path, __filebuf_type*>
357 open(const _Path& __s, ios_base::openmode __mode)
358 { return open(__s.c_str(), __mode); }
359#endif // C++17
360#endif // C++11
361
362 /**
363 * @brief Closes the currently associated file.
364 * @return @c this on success, NULL on failure
365 *
366 * If no file is currently open, this function immediately fails.
367 *
368 * If a <em>put buffer area</em> exists, @c overflow(eof) is
369 * called to flush all the characters. The file is then
370 * closed.
371 *
372 * If any operations fail, this function also fails.
373 */
374 __filebuf_type*
376
377#if __cpp_lib_fstream_native_handle // C++ >= 26
378 /**
379 * @brief The platform-specific file handle type.
380 *
381 * The type is `int` for POSIX platforms that use file descriptors,
382 * or `HANDLE` for Windows, or `FILE*` if the library was configured
383 * with `--enable-cstdio=stdio_pure`.
384 *
385 * @since C++26
386 */
387 using native_handle_type = typename __file_type::native_handle_type;
388
389 /**
390 * @brief Return the platform-specific native handle for the file.
391 * @pre `is_open()` is true.
392 * @return The native file handle associated with `*this`.
393 *
394 * The handle is invalidated when this filebuf is closed or destroyed.
395 *
396 * @since C++26
397 */
398 [[__gnu__::__always_inline__]]
399 native_handle_type
400 native_handle() const noexcept
401 {
402 __glibcxx_assert(is_open());
403 return _M_file.native_handle();
404 }
405#endif
406
407 protected:
408 void
409 _M_allocate_internal_buffer();
410
411 void
412 _M_destroy_internal_buffer() throw();
413
414 // [27.8.1.4] overridden virtual functions
415 virtual streamsize
417
418 // Stroustrup, 1998, p. 628
419 // underflow() and uflow() functions are called to get the next
420 // character from the real input source when the buffer is empty.
421 // Buffered input uses underflow()
422
423 virtual int_type
425
426 virtual int_type
427 pbackfail(int_type __c = _Traits::eof());
428
429 // Stroustrup, 1998, p 648
430 // The overflow() function is called to transfer characters to the
431 // real output destination when the buffer is full. A call to
432 // overflow(c) outputs the contents of the buffer plus the
433 // character c.
434 // 27.5.2.4.5
435 // Consume some sequence of the characters in the pending sequence.
436 virtual int_type
437 overflow(int_type __c = _Traits::eof());
438
439 // Convert internal _CharT sequence to external, char-based
440 // sequence via codecvt.
441 bool
442 _M_convert_to_external(const char_type*, streamsize);
443
444#if ! _GLIBCXX_INLINE_VERSION // ABI compat
445 __attribute__((__always_inline__))
446 bool
447 _M_convert_to_external(char_type* __ibuf, streamsize __ilen)
448 {
449 const char_type* __cibuf = __ibuf;
450 return _M_convert_to_external(__cibuf, __ilen);
451 }
452#endif
453
454 /**
455 * @brief Manipulates the buffer.
456 * @param __s Pointer to a buffer area.
457 * @param __n Size of @a __s.
458 * @return @c this
459 *
460 * If no file has been opened, and both @a __s and @a __n are zero, then
461 * the stream becomes unbuffered. Otherwise, @c __s is used as a
462 * buffer; see
463 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html#io.streambuf.buffering
464 * for more.
465 */
466 virtual __streambuf_type*
467 setbuf(char_type* __s, streamsize __n);
468
469 virtual pos_type
470 seekoff(off_type __off, ios_base::seekdir __way,
472
473 virtual pos_type
474 seekpos(pos_type __pos,
476
477 // Common code for seekoff, seekpos, and overflow
478 pos_type
479 _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state);
480
481 int
482 _M_get_ext_pos(__state_type &__state);
483
484 virtual int
486
487 virtual void
488 imbue(const locale& __loc);
489
490 virtual streamsize
491 xsgetn(char_type* __s, streamsize __n);
492
493 virtual streamsize
494 xsputn(const char_type* __s, streamsize __n);
495
496 // Flushes output buffer, then writes unshift sequence.
497 bool
498 _M_terminate_output();
499
500 /**
501 * This function sets the pointers of the internal buffer, both get
502 * and put areas. Typically:
503 *
504 * __off == egptr() - eback() upon underflow/uflow (@b read mode);
505 * __off == 0 upon overflow (@b write mode);
506 * __off == -1 upon open, setbuf, seekoff/pos (@b uncommitted mode).
507 *
508 * NB: epptr() - pbase() == _M_buf_size - 1, since _M_buf_size
509 * reflects the actual allocated memory and the last cell is reserved
510 * for the overflow char of a full put area.
511 */
512 void
514 {
515 const bool __testin = _M_mode & ios_base::in;
516 const bool __testout = (_M_mode & ios_base::out
518
519 if (__testin && __off > 0)
520 this->setg(_M_buf, _M_buf, _M_buf + __off);
521 else
522 this->setg(_M_buf, _M_buf, _M_buf);
523
524 if (__testout && __off == 0 && _M_buf_size > 1 )
525 this->setp(_M_buf, _M_buf + _M_buf_size - 1);
526 else
527 this->setp(0, 0);
528 }
529 };
530
531 // [27.8.1.5] Template class basic_ifstream
532 /**
533 * @brief Controlling input for files.
534 * @ingroup io
535 *
536 * @tparam _CharT Type of character stream.
537 * @tparam _Traits Traits for character type, defaults to
538 * char_traits<_CharT>.
539 *
540 * This class supports reading from named files, using the inherited
541 * functions from std::basic_istream. To control the associated
542 * sequence, an instance of std::basic_filebuf is used, which this page
543 * refers to as @c sb.
544 */
545 template<typename _CharT, typename _Traits>
546 class basic_ifstream : public basic_istream<_CharT, _Traits>
547 {
548 public:
549 // Types:
550 typedef _CharT char_type;
551 typedef _Traits traits_type;
552 typedef typename traits_type::int_type int_type;
553 typedef typename traits_type::pos_type pos_type;
554 typedef typename traits_type::off_type off_type;
555
556 // Non-standard types:
557 typedef basic_filebuf<char_type, traits_type> __filebuf_type;
558 typedef basic_istream<char_type, traits_type> __istream_type;
559
560 private:
561 __filebuf_type _M_filebuf;
562
563 public:
564 // Constructors/Destructors:
565 /**
566 * @brief Default constructor.
567 *
568 * Initializes @c sb using its default constructor, and passes
569 * @c &sb to the base class initializer. Does not open any files
570 * (you haven't given it a filename to open).
571 */
572 basic_ifstream() : __istream_type(), _M_filebuf()
573 { this->init(&_M_filebuf); }
574
575 /**
576 * @brief Create an input file stream.
577 * @param __s Null terminated string specifying the filename.
578 * @param __mode Open file in specified mode (see std::ios_base).
579 *
580 * @c ios_base::in is automatically included in @a __mode.
581 */
582 explicit
584 : __istream_type(), _M_filebuf()
585 {
586 this->init(&_M_filebuf);
587 this->open(__s, __mode);
588 }
589
590#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
591 /**
592 * @param Create an input file stream.
593 * @param __s Wide string specifying the filename.
594 * @param __mode Open file in specified mode (see std::ios_base).
595 *
596 * @c ios_base::in is automatically included in @a __mode.
597 */
598 basic_ifstream(const wchar_t* __s,
600 : __istream_type(), _M_filebuf()
601 {
602 this->init(&_M_filebuf);
603 this->open(__s, __mode);
604 }
605#endif
606
607#if __cplusplus >= 201103L
608 /**
609 * @brief Create an input file stream.
610 * @param __s std::string specifying the filename.
611 * @param __mode Open file in specified mode (see std::ios_base).
612 *
613 * @c ios_base::in is automatically included in @a __mode.
614 */
615 explicit
618 : __istream_type(), _M_filebuf()
619 {
620 this->init(&_M_filebuf);
621 this->open(__s, __mode);
622 }
623
624#if __cplusplus >= 201703L
625 /**
626 * @brief Create an input file stream.
627 * @param __s filesystem::path specifying the filename.
628 * @param __mode Open file in specified mode (see std::ios_base).
629 *
630 * @c ios_base::in is automatically included in @a __mode.
631 */
632 template<typename _Path, typename _Require = _If_fs_path<_Path>>
633 basic_ifstream(const _Path& __s,
635 : basic_ifstream(__s.c_str(), __mode)
636 { }
637#endif // C++17
638
639 basic_ifstream(const basic_ifstream&) = delete;
640
642 : __istream_type(std::move(__rhs)),
643 _M_filebuf(std::move(__rhs._M_filebuf))
644 { __istream_type::set_rdbuf(&_M_filebuf); }
645#endif // C++11
646
647 /**
648 * @brief The destructor does nothing.
649 *
650 * The file is closed by the filebuf object, not the formatting
651 * stream.
652 */
655
656#if __cplusplus >= 201103L
657 // 27.8.3.2 Assign and swap:
658
660 operator=(const basic_ifstream&) = delete;
661
663 operator=(basic_ifstream&& __rhs)
664 {
665 __istream_type::operator=(std::move(__rhs));
666 _M_filebuf = std::move(__rhs._M_filebuf);
667 return *this;
668 }
669
670 void
671 swap(basic_ifstream& __rhs)
672 {
673 __istream_type::swap(__rhs);
674 _M_filebuf.swap(__rhs._M_filebuf);
675 }
676#endif
677
678 // Members:
679 /**
680 * @brief Accessing the underlying buffer.
681 * @return The current basic_filebuf buffer.
682 *
683 * This hides both signatures of std::basic_ios::rdbuf().
684 */
685 _GLIBCXX_NODISCARD
686 __filebuf_type*
687 rdbuf() const
688 { return const_cast<__filebuf_type*>(&_M_filebuf); }
689
690 /**
691 * @brief Wrapper to test for an open file.
692 * @return @c rdbuf()->is_open()
693 */
694 _GLIBCXX_NODISCARD
695 bool
697 { return _M_filebuf.is_open(); }
698
699 // _GLIBCXX_RESOLVE_LIB_DEFECTS
700 // 365. Lack of const-qualification in clause 27
701 _GLIBCXX_NODISCARD
702 bool
703 is_open() const
704 { return _M_filebuf.is_open(); }
705
706 /**
707 * @brief Opens an external file.
708 * @param __s The name of the file.
709 * @param __mode The open mode flags.
710 *
711 * Calls @c std::basic_filebuf::open(s,__mode|in). If that function
712 * fails, @c failbit is set in the stream's error state.
713 */
714 void
715 open(const char* __s, ios_base::openmode __mode = ios_base::in)
716 {
717 if (!_M_filebuf.open(__s, __mode | ios_base::in))
719 else
720 // _GLIBCXX_RESOLVE_LIB_DEFECTS
721 // 409. Closing an fstream should clear error state
722 this->clear();
723 }
724
725#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
726 /**
727 * @brief Opens an external file.
728 * @param __s The name of the file, as a wide character string.
729 * @param __mode The open mode flags.
730 *
731 * Calls @c std::basic_filebuf::open(__s,__mode|in). If that function
732 * fails, @c failbit is set in the stream's error state.
733 */
734 void
735 open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in)
736 {
737 if (!_M_filebuf.open(__s, __mode | ios_base::in))
739 else
740 this->clear();
741 }
742#endif
743
744#if __cplusplus >= 201103L
745 /**
746 * @brief Opens an external file.
747 * @param __s The name of the file.
748 * @param __mode The open mode flags.
749 *
750 * Calls @c std::basic_filebuf::open(__s,__mode|in). If that function
751 * fails, @c failbit is set in the stream's error state.
752 */
753 void
755 {
756 if (!_M_filebuf.open(__s, __mode | ios_base::in))
758 else
759 // _GLIBCXX_RESOLVE_LIB_DEFECTS
760 // 409. Closing an fstream should clear error state
761 this->clear();
762 }
763
764#if __cplusplus >= 201703L
765 /**
766 * @brief Opens an external file.
767 * @param __s The name of the file, as a filesystem::path.
768 * @param __mode The open mode flags.
769 *
770 * Calls @c std::basic_filebuf::open(__s,__mode|in). If that function
771 * fails, @c failbit is set in the stream's error state.
772 */
773 template<typename _Path>
774 _If_fs_path<_Path, void>
775 open(const _Path& __s, ios_base::openmode __mode = ios_base::in)
776 { open(__s.c_str(), __mode); }
777#endif // C++17
778#endif // C++11
779
780 /**
781 * @brief Close the file.
782 *
783 * Calls @c std::basic_filebuf::close(). If that function
784 * fails, @c failbit is set in the stream's error state.
785 */
786 void
788 {
789 if (!_M_filebuf.close())
791 }
792
793#if __cpp_lib_fstream_native_handle // C++ >= 26
794 using native_handle_type = typename __filebuf_type::native_handle_type;
795
796 [[__gnu__::__always_inline__]]
797 native_handle_type
798 native_handle() const noexcept
799 { return _M_filebuf.native_handle(); }
800#endif
801 };
802
803
804 // [27.8.1.8] Template class basic_ofstream
805 /**
806 * @brief Controlling output for files.
807 * @ingroup io
808 *
809 * @tparam _CharT Type of character stream.
810 * @tparam _Traits Traits for character type, defaults to
811 * char_traits<_CharT>.
812 *
813 * This class supports reading from named files, using the inherited
814 * functions from std::basic_ostream. To control the associated
815 * sequence, an instance of std::basic_filebuf is used, which this page
816 * refers to as @c sb.
817 */
818 template<typename _CharT, typename _Traits>
819 class basic_ofstream : public basic_ostream<_CharT,_Traits>
820 {
821 public:
822 // Types:
823 typedef _CharT char_type;
824 typedef _Traits traits_type;
825 typedef typename traits_type::int_type int_type;
826 typedef typename traits_type::pos_type pos_type;
827 typedef typename traits_type::off_type off_type;
828
829 // Non-standard types:
830 typedef basic_filebuf<char_type, traits_type> __filebuf_type;
831 typedef basic_ostream<char_type, traits_type> __ostream_type;
832
833 private:
834 __filebuf_type _M_filebuf;
835
836 public:
837 // Constructors:
838 /**
839 * @brief Default constructor.
840 *
841 * Initializes @c sb using its default constructor, and passes
842 * @c &sb to the base class initializer. Does not open any files
843 * (you haven't given it a filename to open).
844 */
845 basic_ofstream(): __ostream_type(), _M_filebuf()
846 { this->init(&_M_filebuf); }
847
848 /**
849 * @brief Create an output file stream.
850 * @param __s Null terminated string specifying the filename.
851 * @param __mode Open file in specified mode (see std::ios_base).
852 *
853 * @c ios_base::out is automatically included in @a __mode.
854 */
855 explicit
856 basic_ofstream(const char* __s,
858 : __ostream_type(), _M_filebuf()
859 {
860 this->init(&_M_filebuf);
861 this->open(__s, __mode);
862 }
863
864#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
865 /**
866 * @param Create an output file stream.
867 * @param __s Wide string specifying the filename.
868 * @param __mode Open file in specified mode (see std::ios_base).
869 *
870 * @c ios_base::out | @c ios_base::trunc is automatically included in
871 * @a __mode.
872 */
873 basic_ofstream(const wchar_t* __s,
875 : __ostream_type(), _M_filebuf()
876 {
877 this->init(&_M_filebuf);
878 this->open(__s, __mode);
879 }
880#endif
881
882#if __cplusplus >= 201103L
883 /**
884 * @brief Create an output file stream.
885 * @param __s std::string specifying the filename.
886 * @param __mode Open file in specified mode (see std::ios_base).
887 *
888 * @c ios_base::out is automatically included in @a __mode.
889 */
890 explicit
893 : __ostream_type(), _M_filebuf()
894 {
895 this->init(&_M_filebuf);
896 this->open(__s, __mode);
897 }
898
899#if __cplusplus >= 201703L
900 /**
901 * @brief Create an output file stream.
902 * @param __s filesystem::path specifying the filename.
903 * @param __mode Open file in specified mode (see std::ios_base).
904 *
905 * @c ios_base::out is automatically included in @a __mode.
906 */
907 template<typename _Path, typename _Require = _If_fs_path<_Path>>
908 basic_ofstream(const _Path& __s,
910 : basic_ofstream(__s.c_str(), __mode)
911 { }
912#endif // C++17
913
914 basic_ofstream(const basic_ofstream&) = delete;
915
917 : __ostream_type(std::move(__rhs)),
918 _M_filebuf(std::move(__rhs._M_filebuf))
919 { __ostream_type::set_rdbuf(&_M_filebuf); }
920#endif
921
922 /**
923 * @brief The destructor does nothing.
924 *
925 * The file is closed by the filebuf object, not the formatting
926 * stream.
927 */
930
931#if __cplusplus >= 201103L
932 // 27.8.3.2 Assign and swap:
933
935 operator=(const basic_ofstream&) = delete;
936
938 operator=(basic_ofstream&& __rhs)
939 {
940 __ostream_type::operator=(std::move(__rhs));
941 _M_filebuf = std::move(__rhs._M_filebuf);
942 return *this;
943 }
944
945 void
946 swap(basic_ofstream& __rhs)
947 {
948 __ostream_type::swap(__rhs);
949 _M_filebuf.swap(__rhs._M_filebuf);
950 }
951#endif
952
953 // Members:
954 /**
955 * @brief Accessing the underlying buffer.
956 * @return The current basic_filebuf buffer.
957 *
958 * This hides both signatures of std::basic_ios::rdbuf().
959 */
960 _GLIBCXX_NODISCARD
961 __filebuf_type*
962 rdbuf() const
963 { return const_cast<__filebuf_type*>(&_M_filebuf); }
964
965 /**
966 * @brief Wrapper to test for an open file.
967 * @return @c rdbuf()->is_open()
968 */
969 _GLIBCXX_NODISCARD
970 bool
972 { return _M_filebuf.is_open(); }
973
974 // _GLIBCXX_RESOLVE_LIB_DEFECTS
975 // 365. Lack of const-qualification in clause 27
976 _GLIBCXX_NODISCARD
977 bool
978 is_open() const
979 { return _M_filebuf.is_open(); }
980
981 /**
982 * @brief Opens an external file.
983 * @param __s The name of the file.
984 * @param __mode The open mode flags.
985 *
986 * Calls @c std::basic_filebuf::open(__s,__mode|out). If that
987 * function fails, @c failbit is set in the stream's error state.
988 */
989 void
990 open(const char* __s, ios_base::openmode __mode = ios_base::out)
991 {
992 if (!_M_filebuf.open(__s, __mode | ios_base::out))
994 else
995 // _GLIBCXX_RESOLVE_LIB_DEFECTS
996 // 409. Closing an fstream should clear error state
997 this->clear();
998 }
999
1000#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1001 /**
1002 * @brief Opens an external file.
1003 * @param __s The name of the file.
1004 * @param __mode The open mode flags.
1005 *
1006 * Calls @c std::basic_filebuf::open(__s,__mode|out). If that
1007 * function fails, @c failbit is set in the stream's error state.
1008 */
1009 void
1010 open(const wchar_t* __s, ios_base::openmode __mode = ios_base::out)
1011 {
1012 if (!_M_filebuf.open(__s, __mode | ios_base::out))
1014 else
1015 this->clear();
1016 }
1017#endif
1018
1019#if __cplusplus >= 201103L
1020 /**
1021 * @brief Opens an external file.
1022 * @param __s The name of the file.
1023 * @param __mode The open mode flags.
1024 *
1025 * Calls @c std::basic_filebuf::open(s,mode|out). If that
1026 * function fails, @c failbit is set in the stream's error state.
1027 */
1028 void
1030 {
1031 if (!_M_filebuf.open(__s, __mode | ios_base::out))
1033 else
1034 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1035 // 409. Closing an fstream should clear error state
1036 this->clear();
1037 }
1038
1039#if __cplusplus >= 201703L
1040 /**
1041 * @brief Opens an external file.
1042 * @param __s The name of the file, as a filesystem::path.
1043 * @param __mode The open mode flags.
1044 *
1045 * Calls @c std::basic_filebuf::open(__s,__mode|out). If that
1046 * function fails, @c failbit is set in the stream's error state.
1047 */
1048 template<typename _Path>
1049 _If_fs_path<_Path, void>
1050 open(const _Path& __s, ios_base::openmode __mode = ios_base::out)
1051 { open(__s.c_str(), __mode); }
1052#endif // C++17
1053#endif // C++11
1054
1055 /**
1056 * @brief Close the file.
1057 *
1058 * Calls @c std::basic_filebuf::close(). If that function
1059 * fails, @c failbit is set in the stream's error state.
1060 */
1061 void
1063 {
1064 if (!_M_filebuf.close())
1066 }
1067
1068#if __cpp_lib_fstream_native_handle // C++ >= 26
1069 using native_handle_type = typename __filebuf_type::native_handle_type;
1070
1071 [[__gnu__::__always_inline__]]
1072 native_handle_type
1073 native_handle() const noexcept
1074 { return _M_filebuf.native_handle(); }
1075#endif
1076 };
1077
1078
1079 // [27.8.1.11] Template class basic_fstream
1080 /**
1081 * @brief Controlling input and output for files.
1082 * @ingroup io
1083 *
1084 * @tparam _CharT Type of character stream.
1085 * @tparam _Traits Traits for character type, defaults to
1086 * char_traits<_CharT>.
1087 *
1088 * This class supports reading from and writing to named files, using
1089 * the inherited functions from std::basic_iostream. To control the
1090 * associated sequence, an instance of std::basic_filebuf is used, which
1091 * this page refers to as @c sb.
1092 */
1093 template<typename _CharT, typename _Traits>
1094 class basic_fstream : public basic_iostream<_CharT, _Traits>
1095 {
1096 public:
1097 // Types:
1098 typedef _CharT char_type;
1099 typedef _Traits traits_type;
1100 typedef typename traits_type::int_type int_type;
1101 typedef typename traits_type::pos_type pos_type;
1102 typedef typename traits_type::off_type off_type;
1103
1104 // Non-standard types:
1105 typedef basic_filebuf<char_type, traits_type> __filebuf_type;
1106 typedef basic_ios<char_type, traits_type> __ios_type;
1107 typedef basic_iostream<char_type, traits_type> __iostream_type;
1108
1109 private:
1110 __filebuf_type _M_filebuf;
1111
1112 public:
1113 // Constructors/destructor:
1114 /**
1115 * @brief Default constructor.
1116 *
1117 * Initializes @c sb using its default constructor, and passes
1118 * @c &sb to the base class initializer. Does not open any files
1119 * (you haven't given it a filename to open).
1120 */
1122 : __iostream_type(), _M_filebuf()
1123 { this->init(&_M_filebuf); }
1124
1125 /**
1126 * @brief Create an input/output file stream.
1127 * @param __s Null terminated string specifying the filename.
1128 * @param __mode Open file in specified mode (see std::ios_base).
1129 */
1130 explicit
1131 basic_fstream(const char* __s,
1133 : __iostream_type(0), _M_filebuf()
1134 {
1135 this->init(&_M_filebuf);
1136 this->open(__s, __mode);
1137 }
1138
1139#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1140 /**
1141 * @param Create an input/output file stream.
1142 * @param __s Wide string specifying the filename.
1143 * @param __mode Open file in specified mode (see std::ios_base).
1144 */
1145 basic_fstream(const wchar_t* __s,
1147 : __iostream_type(0), _M_filebuf()
1148 {
1149 this->init(&_M_filebuf);
1150 this->open(__s, __mode);
1151 }
1152#endif
1153
1154#if __cplusplus >= 201103L
1155 /**
1156 * @brief Create an input/output file stream.
1157 * @param __s Null terminated string specifying the filename.
1158 * @param __mode Open file in specified mode (see std::ios_base).
1159 */
1160 explicit
1163 : __iostream_type(0), _M_filebuf()
1164 {
1165 this->init(&_M_filebuf);
1166 this->open(__s, __mode);
1167 }
1168
1169#if __cplusplus >= 201703L
1170 /**
1171 * @brief Create an input/output file stream.
1172 * @param __s filesystem::path specifying the filename.
1173 * @param __mode Open file in specified mode (see std::ios_base).
1174 */
1175 template<typename _Path, typename _Require = _If_fs_path<_Path>>
1176 basic_fstream(const _Path& __s,
1178 : basic_fstream(__s.c_str(), __mode)
1179 { }
1180#endif // C++17
1181
1182 basic_fstream(const basic_fstream&) = delete;
1183
1185 : __iostream_type(std::move(__rhs)),
1186 _M_filebuf(std::move(__rhs._M_filebuf))
1187 { __iostream_type::set_rdbuf(&_M_filebuf); }
1188#endif
1189
1190 /**
1191 * @brief The destructor does nothing.
1192 *
1193 * The file is closed by the filebuf object, not the formatting
1194 * stream.
1195 */
1197 { }
1198
1199#if __cplusplus >= 201103L
1200 // 27.8.3.2 Assign and swap:
1201
1203 operator=(const basic_fstream&) = delete;
1204
1206 operator=(basic_fstream&& __rhs)
1207 {
1208 __iostream_type::operator=(std::move(__rhs));
1209 _M_filebuf = std::move(__rhs._M_filebuf);
1210 return *this;
1211 }
1212
1213 void
1214 swap(basic_fstream& __rhs)
1215 {
1216 __iostream_type::swap(__rhs);
1217 _M_filebuf.swap(__rhs._M_filebuf);
1218 }
1219#endif
1220
1221 // Members:
1222 /**
1223 * @brief Accessing the underlying buffer.
1224 * @return The current basic_filebuf buffer.
1225 *
1226 * This hides both signatures of std::basic_ios::rdbuf().
1227 */
1228 _GLIBCXX_NODISCARD
1229 __filebuf_type*
1230 rdbuf() const
1231 { return const_cast<__filebuf_type*>(&_M_filebuf); }
1232
1233 /**
1234 * @brief Wrapper to test for an open file.
1235 * @return @c rdbuf()->is_open()
1236 */
1237 _GLIBCXX_NODISCARD
1238 bool
1240 { return _M_filebuf.is_open(); }
1241
1242 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1243 // 365. Lack of const-qualification in clause 27
1244 _GLIBCXX_NODISCARD
1245 bool
1246 is_open() const
1247 { return _M_filebuf.is_open(); }
1248
1249 /**
1250 * @brief Opens an external file.
1251 * @param __s The name of the file.
1252 * @param __mode The open mode flags.
1253 *
1254 * Calls @c std::basic_filebuf::open(__s,__mode). If that
1255 * function fails, @c failbit is set in the stream's error state.
1256 */
1257 void
1258 open(const char* __s,
1260 {
1261 if (!_M_filebuf.open(__s, __mode))
1263 else
1264 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1265 // 409. Closing an fstream should clear error state
1266 this->clear();
1267 }
1268
1269#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1270 /**
1271 * @brief Opens an external file.
1272 * @param __s The name of the file.
1273 * @param __mode The open mode flags.
1274 *
1275 * Calls @c std::basic_filebuf::open(__s,__mode). If that
1276 * function fails, @c failbit is set in the stream's error state.
1277 */
1278 void
1279 open(const wchar_t* __s,
1281 {
1282 if (!_M_filebuf.open(__s, __mode))
1284 else
1285 this->clear();
1286 }
1287#endif
1288
1289#if __cplusplus >= 201103L
1290 /**
1291 * @brief Opens an external file.
1292 * @param __s The name of the file.
1293 * @param __mode The open mode flags.
1294 *
1295 * Calls @c std::basic_filebuf::open(__s,__mode). If that
1296 * function fails, @c failbit is set in the stream's error state.
1297 */
1298 void
1299 open(const std::string& __s,
1301 {
1302 if (!_M_filebuf.open(__s, __mode))
1304 else
1305 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1306 // 409. Closing an fstream should clear error state
1307 this->clear();
1308 }
1309
1310#if __cplusplus >= 201703L
1311 /**
1312 * @brief Opens an external file.
1313 * @param __s The name of the file, as a filesystem::path.
1314 * @param __mode The open mode flags.
1315 *
1316 * Calls @c std::basic_filebuf::open(__s,__mode). If that
1317 * function fails, @c failbit is set in the stream's error state.
1318 */
1319 template<typename _Path>
1320 _If_fs_path<_Path, void>
1321 open(const _Path& __s,
1323 { open(__s.c_str(), __mode); }
1324#endif // C++17
1325#endif // C++11
1326
1327 /**
1328 * @brief Close the file.
1329 *
1330 * Calls @c std::basic_filebuf::close(). If that function
1331 * fails, @c failbit is set in the stream's error state.
1332 */
1333 void
1335 {
1336 if (!_M_filebuf.close())
1338 }
1339
1340#if __cpp_lib_fstream_native_handle // C++ >= 26
1341 using native_handle_type = typename __filebuf_type::native_handle_type;
1342
1343 [[__gnu__::__always_inline__]]
1344 native_handle_type
1345 native_handle() const noexcept
1346 { return _M_filebuf.native_handle(); }
1347#endif
1348 };
1349
1350#if __cplusplus >= 201103L
1351 /// Swap specialization for filebufs.
1352 template <class _CharT, class _Traits>
1353 inline void
1356 { __x.swap(__y); }
1357
1358 /// Swap specialization for ifstreams.
1359 template <class _CharT, class _Traits>
1360 inline void
1363 { __x.swap(__y); }
1364
1365 /// Swap specialization for ofstreams.
1366 template <class _CharT, class _Traits>
1367 inline void
1370 { __x.swap(__y); }
1371
1372 /// Swap specialization for fstreams.
1373 template <class _CharT, class _Traits>
1374 inline void
1377 { __x.swap(__y); }
1378#endif
1379
1380_GLIBCXX_END_NAMESPACE_VERSION
1381} // namespace
1382
1383#include <bits/fstream.tcc>
1384
1385#endif /* _GLIBCXX_FSTREAM */
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
Definition type_traits:2971
auto declval() noexcept -> decltype(__declval< _Tp >(0))
Definition type_traits:2743
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:138
basic_string< char > string
A string of char.
Definition stringfwd.h:79
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
Definition postypes.h:73
The actual work of input and output (for files).
Definition fstream:94
virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
Definition fstream.tcc:820
virtual ~basic_filebuf()
The destructor closes the file first.
Definition fstream:259
_If_fs_path< _Path, __filebuf_type * > open(const _Path &__s, ios_base::openmode __mode)
Opens an external file.
Definition fstream:357
__filebuf_type * open(const std::string &__s, ios_base::openmode __mode)
Opens an external file.
Definition fstream:345
virtual void imbue(const locale &__loc)
Changes translations.
Definition fstream.tcc:1017
virtual streamsize xsgetn(char_type *__s, streamsize __n)
Multiple character extraction.
Definition fstream.tcc:660
bool is_open() const
Returns true if the external file is open.
Definition fstream:279
__filebuf_type * close()
Closes the currently associated file.
Definition fstream.tcc:254
void _M_destroy_pback()
Definition fstream:229
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
Definition fstream.tcc:880
virtual int_type pbackfail(int_type __c=traits_type::eof())
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Multiple character insertion.
Definition fstream.tcc:746
virtual int_type overflow(int_type __c=traits_type::eof())
void _M_create_pback()
Definition fstream:212
__filebuf_type * open(const char *__s, ios_base::openmode __mode)
Opens an external file.
Definition fstream.tcc:184
basic_filebuf()
Does not open any files.
Definition fstream.tcc:86
void _M_set_buffer(streamsize __off)
Definition fstream:513
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
Definition fstream.tcc:1000
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
Definition fstream.tcc:791
Controlling input for files.
Definition fstream:547
basic_ifstream()
Default constructor.
Definition fstream:572
~basic_ifstream()
The destructor does nothing.
Definition fstream:653
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
Definition fstream:775
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
Definition fstream:687
void open(const char *__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
Definition fstream:715
basic_ifstream(const char *__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
Definition fstream:583
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
Definition fstream:754
basic_ifstream(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
Definition fstream:633
basic_ifstream(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
Definition fstream:616
void close()
Close the file.
Definition fstream:787
bool is_open()
Wrapper to test for an open file.
Definition fstream:696
Controlling output for files.
Definition fstream:820
basic_ofstream()
Default constructor.
Definition fstream:845
void open(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
Definition fstream:1029
basic_ofstream(const char *__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
Definition fstream:856
void close()
Close the file.
Definition fstream:1062
basic_ofstream(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
Definition fstream:908
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
Definition fstream:962
void open(const char *__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
Definition fstream:990
basic_ofstream(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
Definition fstream:891
~basic_ofstream()
The destructor does nothing.
Definition fstream:928
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
Definition fstream:1050
bool is_open()
Wrapper to test for an open file.
Definition fstream:971
Controlling input and output for files.
Definition fstream:1095
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
Definition fstream:1321
~basic_fstream()
The destructor does nothing.
Definition fstream:1196
basic_fstream(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
Definition fstream:1176
void open(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
Definition fstream:1258
basic_fstream(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
Definition fstream:1161
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
Definition fstream:1299
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
Definition fstream:1230
bool is_open()
Wrapper to test for an open file.
Definition fstream:1239
void close()
Close the file.
Definition fstream:1334
basic_fstream(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
Definition fstream:1131
basic_fstream()
Default constructor.
Definition fstream:1121
basic_istream(__streambuf_type *__sb)
Base constructor.
Definition istream:107
basic_iostream(basic_streambuf< _CharT, _Traits > *__sb)
Constructor does nothing.
Definition istream:1027
basic_streambuf< char_type, traits_type > __streambuf_type
This is a non-standard type.
Definition streambuf:150
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
Definition streambuf:527
char_type * eback() const
Access to the get area.
Definition streambuf:500
char_type * egptr() const
Access to the get area.
Definition streambuf:506
char_type * gptr() const
Access to the get area.
Definition streambuf:503
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
Definition streambuf:573
basic_streambuf()
Base constructor.
Definition streambuf:481
is_default_constructible
Definition type_traits:1276
is_copy_constructible
Definition type_traits:1303
Template class basic_ios, virtual base class for all stream classes.
Definition basic_ios.h:71
void clear(iostate __state=goodbit)
[Re]sets the error state.
Definition basic_ios.tcc:46
void setstate(iostate __state)
Sets additional flags in the error state.
Definition basic_ios.h:167
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
constexpr const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Primary class template codecvt.
Definition codecvt.h:284
static const openmode in
Open for input. Default for ifstream and fstream.
Definition ios_base.h:498
static const openmode out
Open for output. Default for ofstream and fstream.
Definition ios_base.h:501
_Ios_Openmode openmode
This is a bitmask type.
Definition ios_base.h:484
static const openmode app
Seek to end before each write.
Definition ios_base.h:487
_Ios_Seekdir seekdir
This is an enumerated type.
Definition ios_base.h:523
static const openmode trunc
Truncate an existing stream when opening. Default for ofstream.
Definition ios_base.h:504
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
Definition ios_base.h:465
basic_ostream(__streambuf_type *__sb)
Base constructor.
Definition ostream.h:97
Container class for localization functionality.
Class representing stream positions.
Definition postypes.h:88