Back Button
Back to Chapter
C++ Introduction
No items found.
C++ Basics
No items found.
C++ Control Statements
No items found.
C++ Logical Operators
No items found.
C++ Procedural Programming
No items found.
C++ Structural Programming
No items found.
C++ Implementation of OOPS
No items found.
C++ Arrays and Vectors
No items found.
C++ Error Handling
No items found.
C++ File Handling
No items found.
Collapse_Icon
Table of Contents

By now you already how we instruct the computer to give output, using cout standard output stream we can get the output on the display screen.

Now for getting input we make use of cin which is a C++ standard input stream, this instructs the computer to take input from the standard input device which is a keyboard in most cases.

Let us consider this example code to input 2 numbers from the user and give the sum as output:

#include using namespace std; main() { int a; int b; cout<<"enter the value of a:"; cin>>a;//the value entered by the user is stored in the 'a' container cout<<"enter the value of b:"; cin>>b;//the value entered by the user is stored in the 'b' container cout<<"the sum is:"<
Output: enter the value of a:10 enter the value of b:15 the sum is:25

This is how we can input variables from users and display the output.