A simplest I/O program (Input / Output) program in C++, in which input is taken from keyboard as integer and output is displayed to monitor. Its a console program, and you can run it in CodeBlocks editor. Follow the C++ video tutorial given below.
C C++ Java tutorials >> Simplest I/O program >> C++ Coaching Classes
Program with code, description & video tutorial
Input from keyboard (input operator >> extraction / get from operator)
#include <iostream.h> using namespace std; int main() { int a; cout << "Please enter a number for variable a : "; cin >> a; cout << "value of variable a is = " << a; } //( Programme 1 ) _______________________________________ Output of the above program as follows: _______________________________________ Please enter a number for variable a : 76 value of variable a is = 76 _______________________________________
Identifier cin is a predefined object in C++ corresponds to standard input stream, causes the program to wait for the user , to type in a number which is placed in the variable a, The stream represents the keyboard from which input is taken.
Output to display: output operator << put to / insertion operator
#include <iostream.h> int main() { cout << “Hello”; }
Identifier cout is a predefined object in C++ which represents the standard output stream, which flows to the display unit or monitor.
This operator << is called the insertion or put to operator. It directs the content of the variable on its right to the object on its left.
This tutorial and video tutorial is intended for C++ beginners, to learn C++ attend C C++ Java tutorial & coaching classes in Kolkata & online C++ coaching classes
Video Tutorial
Video Transcription
In this program I am showing you how you can take the input from the keyboard in C++ program and how to output the variable which you have taken from the keyboard and display it in the computer monitor
So I am using code blocks editor here for C++.
Here #include <iostream> which is a header file and below that a namespace statement which you have to write for input output programs.
but sometimes you need to write <iostream.h> , here it’s <iostream> you don’t need to bother about that
This is the main function body main C++ program for input output
I have declared variable a .. cout – what does cout? it displays output to display unit via put to operator and cout is the identifier, a predefined object in C++ which represent the standard output stream
which flows to the display unit or monitor, so what you write here will be displayed to the standard output stream
and displayed and flowed to the monitor, and it will be shown to the monitor
and this operator it is actually output operator or put to or insertion operator so what you write here
in this picture I have shown you what to write, through the insertion operator goes to cout object and displayed to the screen
So back to the program again and this is a program, so this will be displayed first
cin is a statement which is needed for taking input from the keyboard or Standard Input stream
this is the same program taking input from the keyboard,
so when you run the program you will get ” please enter a number for variable a” , I typed 76, I have typed it and it will be shown in the next line the value of variable a and the variable value which is 76
The value comes from this a variable this is the output of the program
So the identifier cin is a predefined object in C++ corresponds to standard input stream
causes the program to wait for the user to type in a number which is placed in the variable a
this is the description of the program here so when you type a number it will be placed in the variable a , who is you have declared in this line
so this is the same program here I am taking the input and display in the output
So when you run this program I have typed 34, pressing enter and I get this output
value of variable a is 34 and the program ends and press any key & the program ends in codeblocks editor.
so this is a simplest program for taking input from a keyboard.. taking a number from the keyboard and display in the screen
So the same way you can take any characters,strings, floating point numbers, or any type of numbers, bytes and you can display in the screen
thank you very much I am Bikram from online computer teacher (www.onlinecomputerteacher.net)
For online C++ coaching you can contact “Online Computer Teacher” or search us in Google [Call (+91) 9232603282]