Follow Us

LightBlog

Breaking

Sunday, May 31, 2020

I/O Library Header Files

              I/O Library Header Files
  
 Header File Description
<iostream> It is used to define the cout, cin and cerr objects, which correspond to the standard output stream,standard input stream, and standard error stream, respectively.
<iomanip> It is used to declare services useful for performing formatted I/O, such as setprecision and setw.
<fstream> It is used to declare services for user-controlled file processing.

Standard output stream (cout).

The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console.
Example:
#include <iostream>  
using namespace std;  
int main( ) 
{  
   char ary[] = "Welcome to C++ tutorial";  
   cout << "Value of ary is: " << ary << endl;  
}  
Output:Value of ary is: Welcome to C++ tutorial

Standard input stream (cin).

➡The cin is a predefined object of istream class. It is connected with the standard input device, which is usually a keyboard.
 ➡The cin is used in conjunction with stream extraction operator (>>) to read the input from a console.
Example:
#include <iostream>  
using namespace std;  
int main( ) 
{  
  int age;  
   cout << "Enter your age: ";  
   cin >> age;  
   cout << "Your age is: " << age << endl;  
}  
output:
Enter your age: 22
Your age is: 22

Standard end line (endl)
➡The endl is a predefined object of ostream class. It is used to insert a new line characters and flushes the stream.

Example:
#include <iostream>  
using namespace std;  
int main( ) {  
cout << " Tutorial";     
cout << " Best"<<endl;   
cout << "End of line"<<endl;   
Output:
Tutorial Best
End of line 

 



No comments:

Post a Comment