Skip to main content

How to take input in C++


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

Popular posts from this blog

Variables

Variables You may have been using variables and constants in since your 3rd grade. In any programming language same concept of variables is used which covers more than half of your code. Now is you have worked in C++ or Java or Python or any other programming language you may have used variables. If you are new to programming and you have started with C# its totally OK because you don't need any degree to learn programming. Now what are the variables, to be precise variables are the empty shells which can be filled to their limit and their value can variate with the passage of time as required and manipulated on desire.  Their are few types of variables: Types Examples Integral Types stype, byte, short, ushort, int, unit, long, ulong and char Floating Point Types Floating and Double Decimal Types Decimal Boolean Types True or False value, as assigned Nullable Types Nullable Data Types Declaration Moving on we have some rules for decl...

A Path To Block Chain

 Make it easy Out of oven For a long time blockchain have been known as a theory but bitcoin changed it all. On January 3 2009 bitcoin actually came into existence. Satoshi Nakamoto found something unusual. With the concept of blockchain and mined very first block of bitcoin with reward of 50 bitbucks known as bitcoins. (ok enough with history class lets jump into fun part now). Fun part Bitcoin: Knock knock!  Currency: who is there! Bitcoin: Full stop Trolling banks and financial departments of Europe and America, Bitcoin flew from ground to paramount in no time leaving others waving. For a very long time brokers have been piercing your gold mines with hammers but Bit dude being a good sheriff said "Stop that"   Brokers: "Why" Bit dude: "I wanna take over" Brokers: "With what army" Bit dude: "This army 'anonymous transactions' " Brokers: "Fair enough" With course of few years bitcoin went through so many ups and downs...
Theory of Automata Assignment #2 Part #2 Regular Expression # 6 The set of strings over {a,b} that contain at least two a's or exactly two b's. (a+b)*(a)(b*)a(a+b)*+a*b(a*)b(a*) Regular Expression # 7 The set of strings over {a,b} that contain even length but not multiple of 3 (aa*)(aaa^) Regular Expression # 8 The language over {a,b}contains exactly one double letter.   (ε + b)(ab) ∗aa(ba) ∗(ε + b) + (ε + a)(ba) ∗ bb(ab) ∗(ε + a)