1.unicode文件的打开必须用rb模式。

3.wchar_t str[100] = { 0 }; 这个占200个字节。

2.宽字符对应的处理

  • fgetc fgetwc
  • fputc fputwc
  • fgets fgetws
  • fputs fputws
  • fprintf fwprintf
  • fscanf fwscanf
  • fread ,fwrite

3.操作:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
#include<locale.h> void main1()
{ FILE *pf = fopen("C:\\Users\\yincheng01\\Desktop\\QQ-腾讯通讯录.txt", "rb");
while (!feof(pf))
{
char ch = fgetc(pf);
putchar(ch); }
fclose(pf); system("pause");
} void main2()
{
setlocale(LC_ALL, "zh-CN");  //设置本地化,也就是怎样编码解码
FILE *pfr = _wfopen(L"C:\\Users\\yincheng01\\Desktop\\QQ-腾讯通讯录.txt", L"rb");
FILE *pfw = _wfopen(L"C:\\Users\\yincheng01\\Desktop\\QQc.txt", L"wb");
  //unicode文本文件得用rb打开。
while (!feof(pfr))
{
wchar_t ch = fgetwc(pfr);//获取宽字符
fputwc(ch, pfw);
putwchar(ch);//显示宽字符 }
fclose(pfr);
fclose(pfw);
system("C:\\Users\\yincheng01\\Desktop\\QQc.txt"); system("pause");
} void main3()
{
setlocale(LC_ALL, "zh-CN");
FILE *pfr = _wfopen(L"C:\\Users\\yincheng01\\Desktop\\QQ-腾讯通讯录.txt", L"rb");
FILE *pfw = _wfopen(L"C:\\Users\\yincheng01\\Desktop\\QQ.txt", L"wb");
while (!feof(pfr))
{
wchar_t wstr[] = { };
fgetws(wstr, , pfr);
wprintf(L"%ls",wstr);
fputws(wstr, pfw);//宽字符写入 }
fclose(pfr);
fclose(pfw);
system("C:\\Users\\yincheng01\\Desktop\\QQ.txt");
system("pause");
} void main()
{
setlocale(LC_ALL, "zh-CN");
//wprintf(L"%s", L"hello天朝");
wchar_t wstr[] = { };
fwscanf(stdin, L"%s", wstr);
fwprintf(stdout, L"%s%d%s", L"海华", ,wstr); system("pause");
}
05-07 15:36