What Are Streams in C++? What Are Predefined Streams in C++?

0
614

What Are Streams in C++? What Are Predefined Streams in C++?

What Are Streams in C++? What Are Predefined Streams in C++? this is the most questions in computer science, so In this article What Are Streams in C++? What Are Predefined Streams in C++?.

What Are Streams in C++ What Are Predefined Streams in C++
What Are Streams in C++? What Are Predefined Streams in C++?

What Are Streams in C++?

The stream of characters passed between the programme thread and i/o is referred to as a stream in C++.

In C++, stream groups are used to input and output data from files and I/O devices. These classes have specific features and are used to manage the program’s input and output.
In the C++ programming language, the iostream.h library contains all of the stream classes.

Let’s take a look at the iostream library’s classes now.

The foundation class for all stream classes is the ios class. Input and output streams are both possible. This class specifies members that are unaffected by the way the class’s models are described.

In the C++ programming language, the istream class manages the input source. These data stream objects are used to read and interpret a sequence of characters as input. The input is handled by the cin.

The output stream is handled by the ostream class in the C++ programming language. These output stream objects are used to write data to the screen as a series of characters. In the C++ programming language, the out streams are handled by cout and puts.

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
thdgf
The character array entered using gets is :
thdgf

Predefined Streams in C and C++

Some predefined streams in the C and C++ compilers suggest some regular machines. When a C/C++ programme is started, these predefined streams are automatically opened. The specification of these predefined streams can be found in the stdio.h header file. The definitions of predefined streams in C and C++ are listed below.

NameMeaning
stdinStandard input device
stdoutStandard output device
stderrStandard error output device
stdauxStandard auxiliary device
stdprnStandard printer

Read More –

Standard streams

LEAVE A REPLY

Please enter your comment!
Please enter your name here