C Standard Libraries C++

vswprintf()

Declaration

int vswprintf(wchar_t* wpBuffer,
              size_t uiBuffMax,
              const wchar_t* kwpFormatString,
              va_list qArgList);

Description

This function sends up to "uiBuffMax" wide-characters of the formatted wide-character string given by "kwpFormatString" and the variable argument list "qArgList" to the buffer string "wpBuffer." The function returns the number of characters written to the buffer, not including the null-terminator, if the function call is successful. Otherwise, it returns a negative value to indicate an error.

Example

#include <cwchar>
#include <cstdarg>

int BufferArgs(wchar_t waBuffer[], size_t uiBuffMax,
               wchar_t* wpFormatString, ...)
{
    va_list qArgList;
    va_start(qArgList, wpFormatString);
    int iReturn = vswprintf(waBuffer, uiBuffMax,
        wpFormatString, qArgList);
    va_end(qArgList);
    return iReturn;
}

int main()
{
    wchar_t waBuffer[31];

    // Output an int, a string and a float to the buffer
    int iWritten = BufferArgs(waBuffer, 30, L"%d %ws %f \n",
        8, L"XoaX.net", 3.141593);
    wprintf(L"%d characters written.\n", iWritten);
    wprintf(L"Buffer holds: %ws\n", waBuffer);

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

Output

vswprintf() Output
 

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