Monday, 20 November 2017

C++ Basic Input/Output


C++ Basic Input/Output
Definition
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

There are following header files important to C++ programs −
Sr.No
Header File & Function and Description
1
<iostream>
This file defines the cin, cout, cerr and clog objects, which correspond to the standard input stream, the standard output stream, the un-buffered standard error stream and the buffered standard error stream, respectively.
2
<iomanip>
This file declares services useful for performing formatted I/O with so-called parameterized stream manipulators, such as setw and setprecision.
3
<fstream>
This file declares services for user-controlled file processing. We will discuss about it in detail in File and Stream related chapter.

The Standard Output Stream (cout)

The predefined object cout is an instance of ostream class. The cout object is said to be "connected to" the standard output device, which usually is the display screen. The cout is used in conjunction with the stream insertion operator,
Input:-
#include <iostream>
using namespace std;
 int main() {
   char name[50];
   cout << "Please enter your name: ";
   cin >> name;
   cout << "Your name is: " << name << endl;
}
 OutPut:-
Please enter your name: M.Asif Saeed
Your name is: M.Asif Saeed


No comments:

Post a Comment