...

Programming languages - C++

Back to Course

Lesson Description


Lession - #51 C++ Basic Input/Output


The C++ standard libraries provide an extensive set of input/output capabilities which we will see in subsequent chapters. This chapter will discuss very basic and most common I/O operations required for C++ programming.

C++ I/O occurs in streams, which are sequences of bytes. If bytes flow from a device like a keyboard, a disk drive, or a network connection etc. to main memory, this is called input operation and if bytes flow from main memory to a device like a display screen, a printer, a disk drive, or a network connection, etc., this is called output operation.
 

I/O Library Header Files

Sr.No Header File and Function and Description
1
This file characterizes the cin, cout, cerr and clog objects, which compare to the standard input stream, the standard output stream, the un-buffered standard error stream and the cushioned standard error stream, separately.
2
This file proclaims services helpful for performing arranged I/O with purported parameterized stream controllers, for example, setw and setprecision.
3
This file proclaims services for user-controlled file handling. We will examine about it exhaustively in File and Stream related part.

 

 

The Standard Output Stream (cout>

The predefined object cout is an occurrence of ostream class. The cout object is supposed to be "connected to" the standard output device, which normally is the display screen. The c,out is utilized related to the stream insertion operator, which is composed as << which are two not as much as signs as displayed in the accompanying model.

 

 

 

 

#include 
 
using namespace std;
 
int main(>
{ char str[] = "Hello C++"; cout << "Value of str is : " << str << endl; }

 

 

 

 

The Standard Input Stream (cin>

The predefined object cin is an occasion of istream class. The cin object is supposed to be appended to the standard input device, which for the most part is the keyboard. The cin is utilized related to the stream extraction operator, which is composed as >> which are two more noteworthy than signs as displayed in the accompanying model.

 

 

 

#include 
 
using namespace std;
 
int main(>
{ char name[50]; cout << "Please enter your name: "; cin >> name; cout << "Your name is: " << name << endl; }

 

 

 

The Standard Error Stream (cerr>

The predefined object cerr is an example of ostream class. The cerr object is supposed to be joined to the standard error device, which is additionally a showcase screen yet the item cerr is un-buffered and each stream inclusion to cerr makes its output show up right away.

The cerr is likewise utilized related to the stream insertion operator as displayed in the accompanying model.

 

 

 

#include 
 
using namespace std;
 
int main(>
{ char str[] = "Unable to read...."; cerr << "Error message : " << str << endl; }

 

 

 

The Standard Log Stream (clog>

The predefined object clog is a case of ostream class. The clog object is supposed to be appended to the standard error device, which is additionally a presentation screen yet the article clog is buffered. This implies that every inclusion to clog could make its output be held in a buffer until the buffer is filled or until the buffer is flushed.

The clog is additionally utilized related to the stream insertion operator as displayed in the accompanying model.

 

 

 

#include 
 
using namespace std;
 
int main(>
{ char str[] = "Unable to read...."; clog << "Error message : " << str << endl; }

 

 

 

 

 

 

 

The main diff between C and C++ is that C is a procedural programming language that does not support classes and objects

 

 

 

 

 

 

 

object oriented concepts: encapsulation, abstraction, inheritance, and polymorphism.

 

 

cpp list is a contiguous container while vector is a non-contiguous container i.e list stores the elements on a contiguous memory

 

 

Best IDE for C Programming Language: Top Picks · #1>
Code:: Blocks · #2>
Tabnine · #3>
Eclipse · #4>
CLion · #5>
Visual Studio Code · #6>
NetBeans