You are reading the article Introduction To C++ Stream Classes In C Programming updated in September 2023 on the website Lifecanntwaitvn.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 Introduction To C++ Stream Classes In C Programming
Definition of C++ StreamStream 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.h standard library. Classes associated with the C++ stream include ios class, istream class, and ostream class. Class ios is indirectly inherited from the base class involving iostream class using istream class and ostream class which is declared virtually.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
C++ Stream Classes with ExamplesVarious stream classes in C++ are as follows:
1. istream Classistream being a part of the ios class which is responsible for tackling all the input stream present within the stream. It provides all the necessary and important functions with the number of functions for handling all the strings, chars, and objects within the istream class which comprises all these functions such as get, read, put, etc.
ExampleThis program illustrates the istream class which takes a variable as an input then it makes use of the inbuilt functions like get to tackle and handle the input stream with the output value as an input being provided to the function as shown in the output.
using namespace std; intmain() { char p; cin.get(p); cout<< p; }
Output:
2. ostream ClassThis class as part of the ios class is also considered as a base class that is responsible for handling output stream and provides all the necessary functions for handling chars, strings, and objects such as put, write, etc.
ExampleThis program demonstrates the ostream class as part of the ios class where the first initialized char defined is scanned and then it gets the scanned character and the ostream function takes care to write or put the value to the function.
using namespace std; intmain() { char r_t; cin.get(r_t); cout.put(r_t); }
Output:
3. iostream Classiostream class is the next hierarchy for the ios class which is essential for input stream as well as output stream because istream class and ostream class gets inherited into the main base class. As the name suggests it provides functionality to tackle the objects, strings, and chars which includes inbuild functions of put, puts, get, etc.
Exampleusing namespace std; intmain() { cout.write(“educba_portal”, 9); }
Output:
4. ios Classios class is the highest class in the entire hierarchical structure of the C++ stream. It is also considered as a base class for istream, stream, and streambuf class. It can be said that the ios class is basically responsible for providing all the input and output facilities to all the other classes in the stream class of C++.
ExampleThis program demonstrates the ios class which comprises of the iostream.h as a standard library to derive the values for input and output stream which is part of the ios class as shown in the output.
using namespace std; intmain() { cout<<“Get the value for the _io_stream generation”; return 0; }
Output:
5. istream_withassign ClassThis class is considered as a variant for the istream class that provides the class privilege for the class to assign object. The predefined object which can be called a build in the function of this class is used which is responsible for providing getting the stream facility and thus allows the object to reassign at the run time for different stream objects. Istream_withassign class acts as the primary class for the other classes as part of the istream class.
Exampleusing namespace std; intmain() { char istream_withassign[8]; std::cin.get(istream_withassign, 8); std::cout<< istream_withassign << ‘n’; std::cin.get(istream_withassign, 8); std::cout<< istream_withassign << ‘n’; return 0; }
Output:
6. ostream_withassign ClassThis class is responsible for providing object assigned to the class and is considered as a variant itself for the ostream class of the C++ stream. All the build-in functions such as cout, cerr, clog is the already present objects of the same class and are reassigned at execution time for the different ostream object.
ExampleThis program demonstrates the ostream_withassign class which is responsible for creating the object of the class as shown in the given output.
using namespace std; intmain() { char ostream_withassign[10]; std::cin.get(ostream_withassign, 10); std::cout<<ostream_withassign<< ‘n’; std::cin.get(ostream_withassign, 10); std::cout<<ostream_withassign<< ‘n’; return 0; }
Output:
ConclusionC++ Stream is a very powerful and versatile functionality of the stream classes. They provide programmers an insight for using the predefined and in build functions by modification in the object and the standard libraries of the class for various manipulations and arrangements of the files and folders thus maintaining the hierarchical structure intact for the C++ stream.
Recommended ArticlesThis is a guide to C++ Stream. Here we also discuss the definition and c++ stream classes along with examples and its code implementation. You may also have a look at the following articles to learn more –
You're reading Introduction To C++ Stream Classes In C Programming
Update the detailed information about Introduction To C++ Stream Classes In C Programming on the Lifecanntwaitvn.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!