C++ cstdlib atol() Function
Example
Read the number from the text "8000000 people":
char text[] = "8000000 people";
long people = atol(text);
cout << people;
Definition and Usage
The atol() function reads a whole number at the start of a C-style string, and returns it as a long.
It works like atoi(), but returns a long instead of an int. On many systems, a long can store bigger numbers than an int.
The atol function is defined in the <cstdlib> header file.
Syntax
long atol(const char* str);
Parameter Values
| Parameter | Description |
|---|---|
| str | Required. The C-style string to read the number from. |
Technical Details
| Returns: | A long with the number. If no number is found, it returns 0. |
|---|