C++ Programming Tutorial
C++ Input/Output operation
As in c language use scanf () for input and printf () functions for output.Similarly, we use cin >> for input in c ++ and cout << for output.
Input/Output Library Header Files
Header File | Function and Description |
---|---|
<iostream> |
It is used to define the cout, cin and cerr objects, which correspond to the standard output stream, a standard input stream and standard error stream. |
<iomanip> |
It is used to declare services useful for performing formatted I/O, such as set precision and set. |
<fstream> |
It is used to declare services for user-controlled file processing. |
cout (output stream)
cout => cout means console output. This is the object of the iostream class.
<< => This is called output operator, insertion operator.
#include <iostream> using namespace std; int main( ) { char array[] = "Welcome to C++ programming."; cout << "Display name : " << array << endl; }
Output:
Display name : Welcome to C++ programming.
cin (input stream)
cin => cin means console input. This is the object of the iostream class.
>> => It is called input operator, extraction operator.
#include <iostream> using namespace std; int main( ) { char name[31]; cout << "Enter your name: "; cin >> name; cout << "Your name is: " << name << endl; }
Output:
Enter your name: rama Your name is: rama
endl (End line).
The endl is used to insert a new line characters and flushes the stream.
#include <iostream> using namespace std; int main( ) { cout << "C++ programming Tutorial"; cout << " cprogramming"<Output:
C++ programming Tutorial cprogramming End of line