Input/Output Statements in C++
In C++, input and output operations are commonly performed using the Standard Input/Output Library, which includes the <iostream> header. This library provides the cin and cout objects for reading input and displaying output, respectively. Here's how to use input and output statements in C++:
Input Statements:
Reading Data with
cin:- 1.To read data from the user, you can use the
cinobject, which is associated with the standard input (usually the keyboard). - 2. Use the
>>operator to extract data from the input stream and store it in variables.
- 1.To read data from the user, you can use the
Output Statements:
Displaying Data with cout:
- 1. To output data to the console, you can use the
coutobject, which is associated with the standard output (usually the console). - 2. Use the
<<operator to insert data into the output stream. 20231001103913.png)
- 1. To output data to the console, you can use the
20231001103928.png)
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"Enter 1st number\n";
cin>>a;
cout<<"Enter 2nd number\n";
cin>>b;
c=a+b;
cout<<"Sum is "<<c;
getch();
}
