Menu
Coddy logo textTech

Streams

Lesson 3 of 23 in Coddy's C++ File Handling course.

In C++, there are a variety of classes for file manipulation. More precisely, there are different ways to read from and write to a file.

But we will focus on just the few, easier and most used ones:

  • ifstream - works with input streams and is used to read data from files
  • ofstream - works with output streams and is used to create files and write data to them
  • fstream - represents the general data stream in files and has all the capabilities of both ofstream and ifstream classes. This means it can create files, write data to files, and read data from files. We will mostly include this one in our problems

So, to work with files, to open, close, read from, write to files we need to including two libraries: 

#include <iostream>
#include <fstream>

using namespace std;

int main() {

	// Our code here
	
}

 

Try it yourself

This lesson doesn't include a code challenge.

All lessons in C++ File Handling