The given task is to take an integer as input from the user and print print that integer in C++ language.
In below program, the syntax and procedures to take the integer as input from the user is shown in C++ language.
- The user enters an integer value when asked.
- This value is taken from the user with the help of cin method. The cin method, in C++, reads the value from the console into the specified variable.
cin >> variableOfXType; where >> is the extraction operator and is used along with the object cin for reading inputs. The extraction operator extracts the data from the object cin which is entered using the keyboard.
- For an integer value, the X is replaced with type int. The syntax of cin method becomes as follows then:
cin >> variableOfIntType;
- This entered value is now stored in the variableOfIntType.
- Now to print this value, cout method is used. The cout method, in C++, prints the value passed as the parameter to it, on the console screen.
cout << variableOfXType; where << is the insertion operator. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator (<<).
- For an integer value, the X is replaced with type int. The syntax of cout() method becomes as follows then:
cout << variableOfIntType;
- Hence, the integer value is successfully read and printed.
Enter the integer: 10 Entered integer is: 10
Don't stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- How to Read and Print an Integer value in C
- How to Read and Print an Integer value in Java
- Java Program to Print a Square Pattern for given integer
- How to read content of GeeksforGeeks in an organized way?
- Ways to read input from console in Java
- Read/Write Class Objects from/to File in C++
- lseek() in C/C++ to read the alternate nth byte and write it in another file
- Implement your own tail (Read last n lines of a huge file)
- Count even and odd digits in an Integer
- How to concatenate two Integer values into one?
- Check for integer overflow on multiplication
- Input an integer array without spaces in C
- Find the missing integer in an array if mean is given
- Count the number of holes in an integer
- Integer literal in C/C++ (Prefixes and Suffixes)
- Assigning an integer to float and comparison in C/C++
- String to Integer in Java - parseInt()
- Highest power of 2 less than or equal to given Integer
- Count the minimum steps to reach 0 from the given integer N
- A creative C++ program to Zoom digits of an integer
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.