当前位置: C语言 -- 标准库 -- <wchar.h> -- fputws

fputws函数


概要:
#include <stdio.h>
#include <wchar.h>
int fputws(const wchar_t * restrict s,
      FILE * restrict stream);

描述:

该函数将参数s指向的宽字符串写入参数stream指向的流,终止空宽字符不会被写入。


参数:
const wchar_t * restrict s

wchar_t类型指针,指向将要写入流的宽字符串。

FILE * restrict stream

FILE类型指针,指向写入宽字符串的输出流。


返回值:

如果调用成功,函数返回一个非负值。如果发生写入错误或者编码错误,函数返回EOF


范例:
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 
27 
28 
29 
30 
31 
/*函数fputws范例*/

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>

int main(void)
{
    setlocale(LC_ALL, "");

    FILE *pFile;
    const wchar_t wStr[] = L"谁不会休息,谁就不会工作。";

    /*打开文件。*/
    pFile = fopen("gch.txt", "w");
    if(!pFile)
    {
        perror("Error");
        exit(EXIT_FAILURE);
    }

    /*将数据写入文件。*/
    fputws(wStr, pFile);

    /*关闭文件。*/
    fclose(pFile);

    return 0;
}


结果:

创建一个名为gch.txt的文件,并向其写入:

谁不会休息,谁就不会工作。

:使用Visual Studio编译。


相关内容:
fputwc 将宽字符写入输出流的函数。
putwc 将宽字符写入输出流的函数。
putwchar 将宽字符写入标准输出流的函数。