libstdc++
std::basic_fstream< _CharT, _Traits > Class Template Reference
Inheritance diagram for std::basic_fstream< _CharT, _Traits >:
[legend]

Public Types

typedef basic_filebuf< char_type, traits_type > __filebuf_type
 
typedef basic_ios< char_type, traits_type > __ios_type
 
typedef basic_iostream< char_type, traits_type > __iostream_type
 
typedef basic_istream< _CharT, _Traits > __istream_type
 
typedef basic_ostream< _CharT, _Traits > __ostream_type
 
typedef _CharT char_type
 
typedef traits_type::int_type int_type
 
typedef traits_type::off_type off_type
 
typedef traits_type::pos_type pos_type
 
typedef _Traits traits_type
 

Public Member Functions

 basic_fstream ()
 
 basic_fstream (basic_fstream &&__rhs)
 
 basic_fstream (const basic_fstream &)=delete
 
 basic_fstream (const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
 
 basic_fstream (const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
 
 ~basic_fstream ()
 
void close ()
 
bool is_open ()
 
bool is_open () const
 
void open (const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
 
void open (const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
 
basic_fstreamoperator= (basic_fstream &&__rhs)
 
basic_fstreamoperator= (const basic_fstream &)=delete
 
__filebuf_typerdbuf () const
 
void swap (basic_fstream &__rhs)
 

Protected Member Functions

void swap (basic_iostream &__rhs)
 

Detailed Description

template<typename _CharT, typename _Traits>
class std::basic_fstream< _CharT, _Traits >

Controlling input and output for files.

Template Parameters
_CharTType of character stream.
_TraitsTraits for character type, defaults to char_traits<_CharT>.

This class supports reading from and writing to named files, using the inherited functions from std::basic_iostream. To control the associated sequence, an instance of std::basic_filebuf is used, which this page refers to as sb.

Definition at line 1016 of file fstream.

Constructor & Destructor Documentation

◆ basic_fstream() [1/3]

template<typename _CharT , typename _Traits >
std::basic_fstream< _CharT, _Traits >::basic_fstream ( )
inline

Default constructor.

Initializes sb using its default constructor, and passes &sb to the base class initializer. Does not open any files (you haven't given it a filename to open).

Definition at line 1043 of file fstream.

◆ basic_fstream() [2/3]

template<typename _CharT , typename _Traits >
std::basic_fstream< _CharT, _Traits >::basic_fstream ( const char *  __s,
ios_base::openmode  __mode = ios_base::in | ios_base::out 
)
inlineexplicit

Create an input/output file stream.

Parameters
__sNull terminated string specifying the filename.
__modeOpen file in specified mode (see std::ios_base).

Definition at line 1053 of file fstream.

◆ basic_fstream() [3/3]

template<typename _CharT , typename _Traits >
std::basic_fstream< _CharT, _Traits >::basic_fstream ( const std::string __s,
ios_base::openmode  __mode = ios_base::in | ios_base::out 
)
inlineexplicit

Create an input/output file stream.

Parameters
__sNull terminated string specifying the filename.
__modeOpen file in specified mode (see std::ios_base).

Definition at line 1083 of file fstream.

◆ ~basic_fstream()

template<typename _CharT , typename _Traits >
std::basic_fstream< _CharT, _Traits >::~basic_fstream ( )
inline

The destructor does nothing.

The file is closed by the filebuf object, not the formatting stream.

Definition at line 1118 of file fstream.

Member Function Documentation

◆ close()

template<typename _CharT , typename _Traits >
void std::basic_fstream< _CharT, _Traits >::close ( )
inline

Close the file.

Calls std::basic_filebuf::close(). If that function fails, failbit is set in the stream's error state.

Definition at line 1253 of file fstream.

◆ is_open()

template<typename _CharT , typename _Traits >
bool std::basic_fstream< _CharT, _Traits >::is_open ( )
inline

Wrapper to test for an open file.

Returns
rdbuf()->is_open()

Definition at line 1159 of file fstream.

◆ open() [1/2]

template<typename _CharT , typename _Traits >
void std::basic_fstream< _CharT, _Traits >::open ( const char *  __s,
ios_base::openmode  __mode = ios_base::in | ios_base::out 
)
inline

Opens an external file.

Parameters
__sThe name of the file.
__modeThe open mode flags.

Calls std::basic_filebuf::open(__s,__mode). If that function fails, failbit is set in the stream's error state.

Definition at line 1177 of file fstream.

◆ open() [2/2]

template<typename _CharT , typename _Traits >
void std::basic_fstream< _CharT, _Traits >::open ( const std::string __s,
ios_base::openmode  __mode = ios_base::in | ios_base::out 
)
inline

Opens an external file.

Parameters
__sThe name of the file.
__modeThe open mode flags.

Calls std::basic_filebuf::open(__s,__mode). If that function fails, failbit is set in the stream's error state.

Definition at line 1218 of file fstream.

◆ rdbuf()

template<typename _CharT , typename _Traits >
__filebuf_type* std::basic_fstream< _CharT, _Traits >::rdbuf ( ) const
inline

Accessing the underlying buffer.

Returns
The current basic_filebuf buffer.

This hides both signatures of std::basic_ios::rdbuf().

Definition at line 1151 of file fstream.


The documentation for this class was generated from the following file: