File Streams

Now, we shall learn how to communicate with files using C++.

We'll cover the following...

File streams enable us to work with files. They need the header <fstream>. The file streams automatically manage their file for its whole lifetime.

Whether we use a file stream for input, output, or with the character type char or wchar_t there are various file stream classes:

Class Use
std::ifstream and std::wifstream File stream for the input of data of type char and wchar_t.
std::ofstream and std::wofstream File stream for the output of data of type char and wchar_t.
std::fstream and std::wfstream File stream for the input and output of data of type char and wchar_t.
std::filebuf and std::wfilebuf Data buffer of type char and wchar_t.
...