C Standard Libraries C++

wscanf()

Declaration

int wscanf(const wchar_t* kwpFormatString, ...);

Description

This function reads data from the standard input stream, stdin, and fills in argument field variables as designated by the formatted wide-character string "kwpFormatString" and its associated arguments. If the function is successful, it returns the number of argument fields that were assigned values. Otherwise, it returns WEOF to indicate an error.

Example

#include <cwchar>
#include <cstdio>

int main()
{
    wchar_t waWideString[21];

    wprintf(L"Type in your name and age: ");
    // Read in up to 20 characters of a wide string
    int iFieldsAssigned = wscanf(L"%20ws", waWideString);
    // Empty the input stream for getchar()
    fflush(stdin);
    wprintf(L"You name is %ws\n", waWideString);
    wprintf(L"Assigned fields = %d\n", iFieldsAssigned);

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

Output

wscanf() Output
 

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