![]() |
![]() |
![]() |
C++ Reference: strtol()
strtol()
Declaration
long strtol(const char* kcpString, char** cppEndPointer, int iNumberBase);
Description
Converts a string of numerical characters to a long value. The argument "kcpString" is a pointer to the string, "cppEndPointer" is a pointer to the terminating character, and "iNumberBase" is the number base of the string that is being converted.
Example
#include <iostream>
#include <cstdlib>
int main() {
using namespace std;
// Convert string of binary digits to a long
const int kiBinary = 2;
char caString[] = "1001";
long lNumber = strtol(caString, NULL, kiBinary);
cout << caString << " converts to " << lNumber << " in binary." << endl;
return 0;
}
Output:
![]() |
![]() |
![]() |
| Home | | | Reference | | | Play Games! | | | Blog | | | Forum | | | Site Map | | | Contact Us |





