Hello azumavengers and welcome to my blog. Today we will talk about taking input in C++.
How to take input in C++
There are different ways of taking input for the variables or objects.
Usually programs take input from keyboard or from files on disks or from data base. Right now filing and data base is not our concern so we will discuss about the input given using keyboard.
For taking input from user we use extraction operators ">>". The reserved word used for taking input in cin. Actually cout and cin are the variable instances of the classes declared in iostream. cout is the variable of type ostream and cin is the variable of type istream.
Let's see an example
#include<iostream> using namespace std; void main() { int var1 = 0;//integer cout << "Enter an integer = ";//displays Enter an integer = cin >> var1;//waits for user to enter value system("pause"); }
Here cin>>var1 will stop the program and wait for the user to enter a legal value.
Don't forget to share your views, follow the blog and subscribe to it. Also share
your views below.
Comments
Post a Comment