atol()

Prototype: long atol(const char *string);
Header File: cstdlib or (stdlib.h for C)
Explanation: This function accepts a string and converts it into a long. For example, if "1234" is passed into the function, it will return 1234. It is similar to atoi, except that it can handle larger numbers (up to the maximum size of a long). 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 a long
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
  char a_char[10];
  cin>>a_char;
  cout<<"As a long: "<<atol(a_char);
}
Other Functions