std::basic_ios::bad

bool bad() const; Returns true if non-recoverable error has occurred on the associated stream. Specifically, returns true if badbit is set in rdstate(). See ios_base::iostate for the list of conditions that set badbit. Parameters (none). Return value true if a non-recoverable error has occurred, false otherwise. Example #include <iostream> #include <fstream> #include <cstdlib> int main() { std::ifstream file("test.txt"); if(!file) // operator! is us

std::basic_ios

Defined in header <ios> template< class CharT, class Traits = std::char_traits<CharT> > class basic_ios : public ios_base The class std::basic_ios provides facilities for interfacing with objects that have std::basic_streambuf interface. Several std::basic_ios objects can refer to one actual std::basic_streambuf object. Inheritance diagram. Two specializations for common character types are also provided: Type Definition ios basic_ios<c

std::basic_ifstream::swap

void swap( basic_ifstream& other ); (since C++11) Exchanges the state of the stream with those of other. This is done by calling basic_istream<CharT, Traits>::swap(other) and rdbuf()->swap(other.rdbuf()). Parameters other - stream to exchange the state with Return value (none). Example See also operator= (C++11) moves the file stream (public member function) swap (C++11) swaps two basic_filebuf objects (public member function of std::basic_

std::basic_ifstream::is_open

bool is_open(); (until C++11) bool is_open() const; (since C++11) Checks if the file stream has an associated file. Effectively calls rdbuf()->is_open(). Parameters (none). Return value true if the file stream has an associated file, false otherwise. Example #include <string> #include <fstream> #include <iostream> //this file is called main.cpp bool file_exists(const std::string& str) { std::ifstream fs(str); return fs.is_open(); } int

std::basic_ifstream::open

void open( const char *filename, ios_base::openmode mode = ios_base::in ); (1) void open( const std::string &filename, ios_base::openmode mode = ios_base::in ); (2) (since C++11) Opens and associates the file with name filename with the file stream. Calls setstate(failbit) on failure. Calls clear() on success. (since C++11) 1) Effectively calls rdbuf()->open(filename, mode | ios_base::in). (see std::basic_filebuf::o

std::basic_ifstream::rdbuf

std::basic_filebuf<CharT, Traits>* rdbuf() const; (since C++11) Returns pointer to the underlying raw file device object. Parameters (none). Return value Pointer to the underlying raw file device. Example

std::basic_ifstream::basic_ifstream

basic_ifstream(); (1) explicit basic_ifstream( const char* filename, ios_base::openmode mode = ios_base::in ); (2) explicit basic_ifstream( const string& filename, ios_base::openmode mode = ios_base::in ); (3) (since C++11) basic_ifstream( basic_ifstream&& other ); (4) (since C++11) basic_ifstream( const basic_ifstream& rhs) = delete; (5) (since C++11) Constructs new file stream. 1

std::basic_ifstream::close

void close(); Closes the associated file. Effectively calls rdbuf()->close(). If an error occurs during operation, setstate(failbit) is called. Parameters (none). Return value (none). Notes This function is called by the destructor of basic_ifstream when the stream object goes out of scope and is not usually invoked directly. Example See also is_open checks if the stream has an associated file (public member function) open opens a file and associates it with t

std::basic_ifstream

Defined in header <fstream> template< class CharT, class Traits = std::char_traits<CharT> > class basic_ifstream : public std::basic_istream<CharT, Traits> The class template basic_ifstream implements high-level input operations on file based streams. It interfaces a file-based streambuffer (std::basic_filebuf) with the high-level interface of (std::basic_istream). A typical implementation of std::basic_ifstream holds only one non-derived data me

std::basic_fstream::rdbuf

std::basic_filebuf<CharT, Traits>* rdbuf() const; (since C++11) Returns pointer to the underlying raw file device object. Parameters (none). Return value Pointer to the underlying raw file device. Example