C++ Files and StreamsLast Updated : 14 Jan 2026 In C++ programming we are using the iostream standard library, it provides cin and cout methods for reading from input and writing to output respectively. To read and write from a file we are using the standard C++ library called fstream. Let us see the data types define in fstream library is:
C++ FileStream example: writing to a fileLet's see the simple example of writing to a text file testout.txt using C++ FileStream programming. ExampleCompile and RunOutput: The content of a text file testout.txt is set with the data: Welcome to javaTpoint. C++ Tutorial. C++ FileStream example: reading from a fileLet's see the simple example of reading from a text file testout.txt using C++ FileStream programming. ExampleCompile and RunNote: Before running the code a text file named as "testout.txt" is need to be created and the content of a text file is given below: |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India