C++ Stream Classes Structure


In C++ stream refers to the stream of characters that are transferred between the program thread and i/o.

Stream classes in C++ are used to input and output operations on files and io devices. These classes have specific features and to handle input and output of the program.

The iostream.h library holds all the stream classes in the C++ programming language.

Let's see the hierarchy and learn about them,

Now, let’s learn about the classes of the iostream library.

ios class − This class is the base class for all stream classes. The streams can be input or output streams. This class defines members that are independent of how the templates of the class are defined.

istream Class − The istream class handles the input stream in c++ programming language. These input stream objects are used to read and interpret the input as a sequence of characters. The cin handles the input.

ostream class − The ostream class handles the output stream in c++ programming language. These output stream objects are used to write data as a sequence of characters on the screen. cout and puts handle the out streams in c++ programming language.

Example

OUT STREAM

COUT

 Live Demo

#include <iostream>
using namespace std;
int main(){
   cout<<"This output is printed on screen";
}

Output

This output is printed on screen

PUTS

 Live Demo

#include <iostream>
using namespace std;
int main(){
   puts("This output is printed using puts");
}

Output

This output is printed using puts

IN STREAM

CIN

 Live Demo

#include <iostream>
using namespace std;
int main(){
   int no;
   cout<<"Enter a number ";
   cin>>no;
   cout<<"Number entered using cin is "<

Output

Enter a number 3453
Number entered using cin is 3453

gets

#include <iostream>
using namespace std;
int main(){
   char ch[10];
   puts("Enter a character array");
   gets(ch);
   puts("The character array entered using gets is : ");
   puts(ch);
}

Output

Enter a character array
thdgf
The character array entered using gets is :
thdgf

Updated on: 26-Oct-2023

20K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements