Coders Packet

C++ Program for Read and Write Operation using fstream library.

By Bharti Suraj Ramashanker

Reading and Writing in a file using fstream library in C++ Programming Language. This all comes under File Handling in C++ Programming.

Let us see how we can perform file handling in C++ Programming Language.

Here we will use fstream header file to perform read and write operation.

fstream represents both output Stream and input Stream. So it can read from files and write to files.

We make an object of fstream class using keyword fstream which can be referred to as data type like Int, Float, Double etc. As we can perform a different operation on datatype like 'int', different operations are performed on dataType fstream

In this code, we first create a text file with '.txt' extension(Simple to Edit), then do write operation on it and then read operation.

After reading all the text from a file, File reading is stopped by checking the EOF condition.

---->EOF: End Of File.

After that, We close the file using the close() function. It should be kept in mind to close the file and use it at right time i.e. after performing all operation.

Download Complete Code

Comments

No comments yet