The vswprintf() function is defined in <cwchar> header file.
int vswprintf( wchar_t* buffer, size_t buf_size, const wchar_t* format, va_list vlist );
The vswprintf() function writes the wide string pointed to by format to the wide string buffer. A maximum of (buf_size-1)
wide characters are written to buffer which is followed by a null wide character.
The wide string format may contain format specifiers starting with % which are replaced by the values of variables that are passed as a list vlist.
Format Specifier | Description |
---|---|
% | Prints % |
c | Writes a single character |
s | Writes a character string |
d or i | Converts a signed integer to decimal representation |
o | Converts an unsigned integer to octal representation |
X or x | Converts an unsigned integer to hexadecimal representation |
u | Converts an unsigned integer to decimal representation |
F or f | Converts floating-point number to the decimal representation |
E or e | Converts floating-point number to the decimal exponent notation |
A or a | Converts floating-point number to the hexadecimal exponent |
G or g | Converts floating-point number to either decimal or decimal exponent notation |
n | Returns the number of characters written so far by this call to the function. The result is written to the value pointed to by the argument |
p | Writes an implementation defined character sequence defining a pointer. |
%[flags][width][.precision][length]specifier
#include <cwchar>
#include <cstdarg>
#include <clocale>
void write(wchar_t* buffer, size_t buf_size, const wchar_t *fmt, ...)
{
va_list args;
va_start(args, fmt);
vswprintf(buffer, buf_size, fmt, args);
va_end(args);
}
int main ()
{
wchar_t str[] = L"\u0684 \u06b1 \u06aa \u06a3 \u0684";
wchar_t buffer[50];
setlocale(LC_ALL, "en_US.UTF-8");
write(buffer, 50, L"Arabic Letters: %ls\n", str);
wprintf(L"%ls", buffer);
return 0;
}
When you run the program, the following will be written to example.txt:
Arabic Letters: ڄ ڱ ڪ ڣ ڄ