0% found this document useful (0 votes)
35 views2 pages

C++ Basic Input Output

The document discusses C++ input/output operations using streams. It flows from and to devices like printers or networks. Common header files for I/O are described like <iostream> for cout, cin and cerr. Examples show how to use cout for output, cin for input, and endl to insert newlines.

Uploaded by

patrickmwenda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

C++ Basic Input Output

The document discusses C++ input/output operations using streams. It flows from and to devices like printers or networks. Common header files for I/O are described like <iostream> for cout, cin and cerr. Examples show how to use cout for output, cin for input, and endl to insert newlines.

Uploaded by

patrickmwenda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ Basic Input/Output

C++ I/O operation is using the stream concept. Stream is the sequence of bytes or flow of data. It
makes the performance fast.
If bytes flow from main memory to device like printer, display screen, or a network connection, etc,
this is called as output operation.
If bytes flow from device like printer, display screen, or a network connection, etc to main memory,
this is called as input operation.

I/O Library Header Files


Let us see the common header files used in C++ programming are:

Header
Function and Description
File
It is used to define the cout, cin and cerr objects, which correspond to standard output
<iostream>
stream, standard input stream and standard error stream, respectively.
It is used to declare services useful for performing formatted I/O, such as setprecision
<iomanip>
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 of a program
#include <iostream>
using namespace std;
int main() {
char str[] = "Hello C++";
cout << "Value of str is : " << str << endl;
}
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 of a programming
#include <iostream>
using namespace std;
int main() {
char name[50];
cout << "Please enter your name: ";
cin >> name;
cout << "Your name is: " << name << endl;

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 of a programming
#include <iostream>
using namespace std;
int main() {
cout << C++ Tutorial";
cout << " Javatpoint"<<endl;
cout << "End of line"<<endl;
}

You might also like