C Standard Libraries C++

strtoul()

Declaration

unsigned long strtoul(const char* kcpString,
                      char** cppEndPointer,
                      int iNumberBase);

Description

Converts a string of numerical characters to an unsigned 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 an unsigned long
    const int kiBinary = 2;
    char caString[] = "1001";
    unsigned long ulNumber = strtoul(caString, NULL, kiBinary);
    cout << caString << " converts to " << ulNumber << " in binary." << endl;
    return 0;
}

Output

strtoul() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.