C Standard Libraries C++

swprintf()

Declaration

int swprintf(wchar_t* wpBuffer,
              size_t uiBuffMax,
              const wchar_t* kwpFormatString, ...);

Description

This function stores up to "uiBuffMax" characters of the the formatted wide-character string "kwpFormatString" in the wide-character array "wpBuffer." If successful, the function returns the number of characters put into "wpBuffer." Otherwise, it returns -1 to indicate ar error.

Example

#include <cwchar>

int main()
{
    using namespace std;
    const unsigned int kuiMaxBuffer = 20;
    wchar_t waBuffer[kuiMaxBuffer + 1];

    // Put a string in the buffer
    int iCharCount = swprintf(waBuffer, kuiMaxBuffer,
        L"%s", L"XoaX.net");
    wprintf(L"%d characters were stored.\n", iCharCount);
    wprintf(L"The buffer holds: %s.\n", waBuffer);

    // Try to put too many characters in the buffer
    iCharCount = swprintf(waBuffer, kuiMaxBuffer,
        L"%s video tutorials", L"XoaX.net");
    wprintf(L"%d characters were stored.\n", iCharCount);
    wprintf(L"The buffer holds: %s.\n", waBuffer);

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

Output

swprintf() Output
 

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