How to Read and Print an Integer value in C++ Last Updated : 03 Jul, 2023 Comments Improve Suggest changes Like Article Like Report The given task is to take an integer as input from the user and print that integer in C++ language. In this article, we will learn how to read and print an integer value. In the below program, the syntax and procedures to take the integer as input from the user is shown in C++ language. Standard Input StreamThe user enters an integer value when asked.This value is taken from the user with the help of the cin method. The cin method, in C++, reads the value from the console into the specified variable. Syntax: cin >> variableOfXType;Here, >> 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 the type int. The syntax of the 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. Standard Output StreamThe cout method, in C++, prints the value passed as the parameter to it, on the console screen. Syntax: cout << variableOfXType;Here, << 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 the type int. The syntax of cout() method becomes as follows then: cout << variableOfIntType;Hence, the integer value is successfully read and printed. Below is the C++ program to read and print an integer value: C++ // C++ program to take an integer // as input and print it #include <iostream> using namespace std; // Driver code int main() { // Declare the variables int num; // Input the integer cout << "Enter the integer: "; cin >> num; // Display the integer cout << "Entered integer is: " << num; return 0; } Output Enter the integer: 10Entered integer is: 10 Comment More infoAdvertise with us Next Article How to Read and Print an Integer value in C++ R RishabhPrabhu Follow Improve Article Tags : C++ Computer Science Fundamentals CPP-Basics Practice Tags : CPP Similar Reads How to Take Input in Array in C++? Arrays in C++ are derived data types that can contain multiple elements of the same data type. They are generally used when we want to store multiple elements of a particular data type under the same name. We can access different array elements using their index as they are stored sequentially in th 3 min read Integer literal in C/C++ (Prefixes and Suffixes) Integer literal is a type of literal for an integer whose value is directly represented in source code. For example, in the assignment statement x = 1, the string 1 is an integer literal indicating the value 1, while in the statement x = 0x10 the string 0x10 is an integer literal indicating the valu 4 min read A creative C++ program to Zoom digits of an integer Write a C (or C++) program to ZOOM (magnify) the digits of an integer. It should take an integer from the user and display each digit of the integer in magnified form using some pattern. Examples: Input : 123 Output : @ @@ @ @ @@@@@ ------------------------------- @@@@ @ @ @ @ @@@@ ----------------- 4 min read Reading Lines by Lines From a File to a Vector in C++ STL Prerequisites: STL in C++Vector in C++File handling in C++ The Standard Template Library (STL) is a set of C++ template classes to provide common programming data structures and functions such as lists, stacks, arrays, etc. It is a library of container classes, algorithms, and iterators. Vector in C 2 min read Representation of Int Variable in Memory in C++ To understand the Representation of int variable in memory in C/C++ below is the basic program to create a variable and its size. Usually, the value of an int variable is stored in a series of bytes that are represented as the variable's representation as memory. Depending on the hardware and compil 5 min read C++ Program to Print Your Own Name Printing your own name means displaying your name on the computer screen. In this article, we will learn how to print your own name using a C++ program.ExamplesInput: name = "Anmol"Output: AnmolExplanation: Given name is printed on the output screen.Input: name = "Alex"Output: AlexExplanation: Given 3 min read C++ Program to Convert String to Integer Given a string of digits, the task is to convert the string to an integer. Examples: Input : str = "12345" Output : 12345 Input : str = "876538"; Output : 876538 Input : str = "0028"; Output : 28 CPP // C++ program to convert String into Integer #include <bits/stdc++.h> using namespace std; // 1 min read Extract all integers from string in C++ Given a string, extract all integers words from it. Examples : Input : str = "geeksforgeeks 12 13 practice" Output : 12 13 Input : str = "1: Prakhar Agrawal, 2: Manish Kumar Rai, 3: Rishabh Gupta" Output : 1 2 3 Input : str = "Ankit sleeps at 4 am." Output : 4 The idea is to use stringstream:, objec 2 min read Read a record from a File in C++ using seekg() and tellg() Given that a binary file "student.data" is already loaded in the memory of the computer with the record of 100 students, the task is to read the Kth record and perform some operations.seekg() is a function in the iostream library (part of the standard library) that allows you to seek to an arbitrary 2 min read std::stoul and std::stoull in C++ std::stoul Convert string to unsigned integer. Parses str interpreting its content as an integral number of the specified base, which is returned as an unsigned long value. unsigned long stoul (const string& str, size_t* idx = 0, int base = 10); Parameters : str : String object with the represen 3 min read Like