std::ios_base::ios_base
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
Buffers
(C++23)
(C++98/26*)
(C++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
Synchronized Output
(C++20)
Types
Error category interface
(C++11)
(C++11)
std::ios_base
Member functions
ios_base::ios_base
Formatting
Locales
Internal extensible array
Miscellaneous
Member classes
Member types
(1)
private:
ios_base( const ios_base& );
(until C++11)
ios_base( const ios_base& );
public:
ios_base( const ios_base& ) = delete;
(since C++11)
ios_base( const ios_base& ) = delete;
protected:
ios_base();
(2)
ios_base();
1) The copy constructor is private(until C++11)deleted(since C++11): streams are not copyable.
2) The default constructor is protected: only derived classes may construct
std::ios_base
. The internal state is undefined after the construction. The derived class must call std::basic_ios::init() to complete initialization before first use or before destructor; otherwise the behavior is undefined.[edit] Notes
The same applies to the constructors of the next class in the I/O hierarchy, std::basic_ios . Further-derived classes (std::istream and std::ostream ) are always constructed with a concrete stream buffer object and call std::basic_ios::init(), possibly more than once, to complete initialization of their virtual base.
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 50 | C++98 | the copy constructor was not specified | specified as private |
LWG 220 | C++98 | the behavior of destroying a std::ios_base object before calling its init() was not clear |
the behavior is undefined in this case |
LWG 1249 | C++98 | initialization did not need to be completed before first use | also needs to be completed |