Basic input and output operations
First Program in CPP
When learning C++, the first program you write is generally a turning point because it summarizes input, processing, and output. The goal of this pilot program is straightforward: ask the user for a number, then repeat it back. Let us break down this classic C++ program, examining its various parts and features.
Program:
#include<iostream.h>
using namespace std;
int main() {
int a;
cout<<"enter a number"; //input statement
cin>>a;
cout<<"the number is : "<<a; //output statement
return 0;
}
Output Statement (cout)
The cout is a predefined object that represents the standard output stream
Example:
cout<< “C++ is better than c”;
Causes the string in quotation marks to be displayed on the screen.
Input Statement (cin)
The cin is a predefined object that represents the standard input stream
The operator >> is called the extraction or get from the operator.
Example
cin>>a;
The value given through the keyboard will be stored in the variable ‘a’.
Comments