Convert number string to integers in C++

C++Server Side ProgrammingProgramming

Here we will see how to convert a number string to integer type data. We can solve this problem by using the atoi() function. This function takes string as input and converts into integer data.

The atoi() function is present in the <cstdlib> library.

Input: A number string “1234”
Output: 1234


Step 1: Take a number string
Step 2: Convert it to integer using atoi() function
Step 3: Print the result.
Step 4: End

Example Code

 Live Demo

using namespace std;
main() {
   int n;
   char num_string[20] = "1234";
   n = atoi(num_string);
   cout << n;


Updated on 30-Jul-2019 22:30:25