The File I/O Classes in C++


Simple C++ Tutorials

The ifstream class derives from the istream class, and enables users to access files and read data from them. The ofstream class derives from the ostream class, and enables users to access files and write data to them. The fstream class is derived from both the ifstream and ofstream classes, and enables users to access files for both data input and output. These functions are defined in the fstream header file.

Declaring input and ouput objects is simple.

#include <fstream>

using namespace std;

int main(void){

    //input stream object
    ifstream infile;

    //output stream object
    ofstream outfile;

    return 0;

}

The open() function is a member of the ifstream or ofstream class; the function in its most basic form takes a single argument, the path to the desired file. We can check the ifstream or ofstream object directly as a binary value to test whether or…

View original post 322 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s