0% found this document useful (0 votes)
99 views3 pages

C++ Stream Classes Explained

The document discusses the hierarchy of stream classes in C++, noting that the iostream library contains classes like ios, istream, and ostream that handle input/output operations. The ios class is the base class for all stream classes and defines members independent of templates, while istream handles input streams and ostream handles output streams to write data as a sequence of characters. Examples are provided demonstrating the use of input streams like cin and gets and output streams like cout and puts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views3 pages

C++ Stream Classes Explained

The document discusses the hierarchy of stream classes in C++, noting that the iostream library contains classes like ios, istream, and ostream that handle input/output operations. The ios class is the base class for all stream classes and defines members independent of templates, while istream handles input streams and ostream handles output streams to write data as a sequence of characters. Examples are provided demonstrating the use of input streams like cin and gets and output streams like cout and puts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

++ 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

#include <iostream>

using namespace std;

int main(){

   cout<<"This output is printed on screen";

Output

This output is printed on screen

PUTS

#include <iostream>

using namespace std;

int main(){

   puts("This output is printed using puts");

Output

This output is printed using puts

IN STREAM
CIN

#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


abcd
The character array entered using gets is :
abcd

You might also like