atoi()

Prototype: int atoi(const char *string);
Header File: stdlib.h (C) or cstdlib (C++)
Explanation: This function accepts a string and converts it into an integer. For example, if "1234" is passed into the function, it will return 1234, an integer. If the string contains a decimal place, the number will be truncated. Eg, "104.21" will be returned as 104.




Example:
//Example reads in a string, and converts it to an integer
#include <cstdlib>
#include <iostream>
int main()
{
  char a_char[10];
  cin>>a_char;
  cout<<"As an integer: "<<atoi(a_char);
}
Other Functions