What is meant by stream? Write a program that reads content of file data.txt and displays the content in monitor.

Stream in C++ means a stream of characters that gets transferred between the program thread and input or output. There are a number of C++ stream classes eligible and defined which is related to the files and streams for providing input-output operations.

All the classes and structures maintaining the file and folders with hierarchies are defined within the file with iostream standard library. Classes associated with the C++ stream include ios class, istream class, and ostream class.

Program to read data from file:

#include <iostream>
#include <fstream>
using namespace std;

int main() {
fstream file;
file.open("data.txt", ios::in);

if (!file) {
cout << "File Doesn't Exists!!!" << endl;
}else {
char ch;
while (1) {
file >> ch;
if (file.eof())
break;
cout << ch;
}
}
file.close();

return 0;
}