File Handling By Using File Stream In C++
First, you have to learn about the file... A file is a medium for storing data/information for a useful purpose in the Future. A file is used to store data/information in terms of a sequence of bytes. Filestore data that is in the form of binary or text form.
How to Use Stream
in order to use streams in c++, we need to use fstream header file.
syntax
#include<fstream>
What kind of Streams are available in C++
There are different kinds of streams are available in C++.
- ofstream
- ifstream
- fstream
ofstream in C++
ofstream is used to write files using C++ program. If we use ofstream header file instead of fstream header file we can only perform write operations in c++.
syntax
#include<ofstream>
ifstream in C++
ifstream is used to read the file using c++ program. If we use ifstream header file instead of fstream header file we can only perform read operations in ++.
syntax
#include <ifstream>
fstream in C++
the fstream header file is used to perform both types of operations i.e. write and read
syntax
#include <fstream>
For Further Operations we use Flags
to read about flags click on it
Code Example Using fstream Header File
In this code, we perform both types of operation i.e read and write using the fstream header file.
File Handling By Using File Stream In C++