function
<cwchar>
vfwprintf
int vfwprintf (FILE* stream, const wchar_t* format, va_list arg);
Write formatted data from variable argument list to stream
Writes the C wide string pointed by format to the stream, replacing any format specifier in the same way as printf does, but using the elements in the variable argument list identified by arg instead of additional function arguments.
Internally, the function retrieves arguments from the list identified by arg as if va_arg was used on it, and thus the state of arg is likely altered by the call.
In any case, arg should have been initialized by va_start at some point before the call, and it is expected to be released by va_end at some point after the call.
The external representation of wide characters in files are multibyte characters: These are obtained as if wcrtomb was called to convert each wide character (using the stream's internal mbstate_t object).
This is the wide character equivalent of vfprintf (<cstdio>).
Parameters
- stream
- Pointer to a FILE object that identifies an output stream.
The stream shall not have an orientation yet, or be wide-oriented (the first i/o operation on a stream determines whether it is byte- or wide- oriented, see fwide).
- format
- C wide string that contains a format string that follows the same specifications as format in printf (see printf for details).
Notice that all format specifiers have the same meaning as in printf; therefore, %lc shall be used to write a wide character (and not %c), as well as %ls shall be used for wide strings (and not %s).
- arg
- A value identifying a variable arguments list initialized with va_start.
va_list is a special type defined in <cstdarg>.
Return Value
On success, the total number of characters written is returned.
If a writing error occurs, the error indicator (ferror) is set and a negative number is returned.
If a multibyte character encoding error occurs while writing wide characters, errno is set to EILSEQ and a negative number is returned.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
/* vfprintf example */
#include <stdio.h>
#include <stdarg.h>
#include <wchar.h>
void WriteWideFormatted (FILE * stream, const wchar_t * format, ...)
{
va_list args;
va_start (args, format);
vfwprintf (stream, format, args);
va_end (args);
}
int main ()
{
FILE * pFile;
pFile = fopen ("myfile.txt","w");
WriteWideFormatted (pFile,L"Call with %d variable argument.\n",1);
WriteWideFormatted (pFile,L"Call with %d variable %ls.\n",2,L"arguments");
fclose (pFile);
return 0;
}
| |
The example demonstrates how the WriteWideFormatted can be called with a different number of arguments, which are on their turn passed to the vfwprintf function.
myfile.txt would contain:
myfile.txt |
Call with 1 variable argument.
Call with 2 variable arguments. |
See also
- vfprintf
- Write formatted data from variable argument list to stream (function
)
- vwprintf
- Print formatted data from variable argument list to stdout (function
)
- vswprintf
- Write formatted data from variable argument list to sized buffer (function
)
- fwprintf
- Write formatted data to stream (function
)
- wprintf
- Print formatted data to stdout (function
)