C++ fputws()

The fputws() function in C++ writes a wide string completely except the terminating null wide character to the given output file stream.

The fputws() function is same as executing fputc() repeatedly.

It is defined in <cwchar> header file.

fputws() prototype

int fputws( const wchar_t* str, FILE* stream );

The fputws() function writes all the character stored in the wide string str to the output file stream except the terminating null wide character.

fputws() Parameters

  • str: Pointer to an wide character array that stores the wide string to be written.
  • stream: The output file stream to write the characters.

fputws() Return value

  • On success, the fputws() function returns a nonnegative value.
  • On failure it returns EOF and sets the error indicator on stream.

Example: How fputws() function works?

#include <cwchar>
#include <cstdio>
#include <clocale>

int main()
	setlocale(LC_ALL, "en_US.UTF-8");
	wchar_t line[] = L"C++ ċăn haʼnđle tĥeșë veɍƴ ŵeįrd čhāråcŧerƨ";
	fputws(line, stdout);
	return 0;

When you run the program, the output will be:

C++ ċăn haʼnđle tĥeșë veɍƴ ŵeįrd čhāråcŧerƨ