C Standard Libraries C++

wcstol()

Declaration

long wcstol(const wchar_t* kwpString, wchar_t** wppEndPtr, int iBase);

Description

This function converts the all of the digits in the wide-character string "kwpString" up to the wide character "wppEndPtr" to a long value using the value "iBase" as the number base for digits. The function returns the converted value, is successful. Otherwise, it returns 0 to indicate an error or LONG_MAX or LONG_MIN to indicate overflow.

Example

#include <cwchar>

int main()
{
    const wchar_t kwaWideString[] = L"101 XoaX.net";
    const wchar_t* kwpWidePtr = kwaWideString;

    // Convert the string to a decimal value
    long lConvert = wcstol(kwaWideString, NULL, 10);
    wprintf(L"Decimal Value %d\n", lConvert);
    wprintf(L"Original String: %ws\n", kwaWideString);

    // Convert the string to a binary value
    lConvert = wcstol(kwaWideString, NULL, 2);
    wprintf(L"Binary Value %d\n", lConvert);
    wprintf(L"Original String: %ws\n", kwaWideString);

    // Keep the window open until "Enter" is pressed
    getwchar();
    return 0;
}

Output

wcstol() Output
 

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