The wscanf() function is defined in <cwchar> header file.
int wscanf( const char* format, ... );
The wscanf() function reads the data from stdin and stores the values into the respective variables.
Format Specifier | Description |
---|---|
% | Matches the literal % |
c | Matches a single character or multiple characters. If width is defined, matches exactly width characters. |
s | Matches consecutive non whitespace characters. If width is defined, matches exactly width characters or until first whitespace is found. |
[set] | Matches a non empty sequence of character from the given set of characters. If ^ is present at the beginning of set, then all the characters not in set are matched. |
d | Matches a decimal integer. |
i | Matches an integer. |
o | Matches an unsigned octal integer. |
X or x | Matches an unsigned hexadecimal integer. |
u | Matches an unsigned decimal integer. |
A or a, E or e, F or f, G or g | Matches a floating-point number. |
n | Returns the number of characters read so far. |
p | Matches an implementation defined character sequence defining a pointer. |
%[*][width][length]specifier
#include <cwchar>
#include <clocale>
#include <cwctype>
#include <iostream>
using namespace std;
int main()
{
wchar_t hebrew_str[] = L"\u05D0 \u05D1 \u05E1 \u05D3 \u05EA";
wchar_t ch;
setlocale(LC_ALL, "en_US.UTF-8");
wprintf(L"Enter a wide character: ");
wscanf(L"%lc",&ch);
if (iswalnum(ch))
wcout << ch << L" is alphanumeric." << endl;
else
wcout << ch << L" is not alphanumeric." << endl;
return 0;
}
When you run the program, a possible output will be:
Enter a wide character: ∭ ∭ is not alphanumeric.