Header Files in C++ are used to provide the functions and facilities that is used in our program to make our task easy to do and better way to perform.
Header files provides the way through which you can print or take input in our program which is a very basic functionality.
Header File
Function and Description
<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.
<iomanip>
This file declares services useful for performing formatted I/O with so-called parameterized stream manipulators, such as setw and setprecision.
<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):
It is an instance of ostream class. It is used to display message from the program.
#include <iostream>
using namespace std;
int main( )
{
char str[] = "Hello C++";
cout << "Value of str is : " << str << endl;
}
The standard input stream (cin):
It is an instance of istream class.It is used to take input from the user.
#include <iostream>
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 instance of ostream class. It is used to define error message.
#include <iostream>
using namespace std;
int main( )
{
char str[] = "Unable to read....";
cerr << "Error message : " << str << endl;
}
0 Comment(s)