filmov
tv
Lecture 2 - Taking User Input | C/C++ Video Tutorials and Lectures for Beginners

Показать описание
Transcription
=============
We shall learn how to obtain an input from the user.
We shall ask the user to enter an int number for his age.
Then we shall store the input in a variable, and finally display it back to the monitor.
Write the usual code till the main function.
This statement prompts the user to enter a number for his age.
Next we create a variable to store the input from the user.
This statement reads the input from the monior and pushes it into our variable.
"cin" stands for console input.
So this statement reads the console input and stores the data into our variable.
The direction of the arrows indicates the direction in which the data moves.
The data is being streamed from the monitor towards the variable.
Here we are displaying the age entered by the user.
We haven't put age in double quotes because it is a variable.
If we put age in quotes it would be spelt back as plain english text.
There is another thing that needs to be seen here. We have chained the double arrows.
The double arrows pointing towards the left are called insertion operators.
While those pointing towards the right are called extraction operators.
It is possible to chain both the extraction and insertion operators.
But it is more common to chain the insertion operators as we have done.
Lastly, complete the function by writing the return statement.
This is how we can obtain user input using C++.
Thanks !
Комментарии