Using atoi() function : char array string « String « C++






Using atoi() function

  
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
   char buffer[80];
   cout << "Enter a number: ";
   cin >> buffer;

   int number;
   number = atoi(buffer);
   cout << "Here's the number: " << number << endl;

   int sum = atoi(buffer) + 5;
   cout << "Here's sum: " << sum << endl;
   return 0;
}
  
    
  








Related examples in the same category

1.Demonstrate the basic null-terminated string functions.
2.Operator pointer
3.Count spaces, punctuation, digits, and letters.
4.Convert char array to upper case
5.Using strcpy() to assign value from one char array to another char array
6.Using strncpy() to assign one char array to another char array
7.Using strcpy and string terminator
8.Using strncpy() and string terminator
9.Get the string length
10.Using strcat() and strncat().
11.Filling an Array
12.Use strlen() to get the length of a char array buffer