function
<cwchar>

fputws

int fputws (const wchar_t* ws, FILE* stream);
Write wide string to stream
Writes the wide C string pointed by ws to the stream.

The function begins copying from the address specified (ws) until it reaches the terminating null wide character. This terminating null wide character is not copied to the stream.

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 fputs (<cstdio>).

Parameters

ws
C wide string with the content to write to the stream.
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).

Return Value

On success, a non-negative value is returned.
If a multibyte character encoding error occurs, errno is set to EILSEQ and EOF is returned.
If a writing error occurs, the function sets the error indicator (ferror) and also returns EOF.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* fputws example */
#include <stdio.h>

int main ()
{
   FILE * pFile;
   wchar_t sentence [256];

   wprintf (L"Enter sentence to append: ");
   fgetws (sentence,255,stdin);
   pFile = fopen ("mylog.txt","a");
   fputws (sentence,pFile);
   fclose (pFile);
   return 0;
}

This program allows to append a line to a file called mylog.txt each time it is run.

See also