字转换:wctomb、mbtowc,wc 指 Wide charactor,mb 指 Multi-byte。\r\n字符串转换:wcstombs、mbstowcs,wcs 和 mbs 的 s 指 string。\r\n\r\n这 4 个
函数是 C 标准函数库函数中的。如果只是在 Windows 平台下编程,可直接调用 Windows API 函数 WideCharToMultiByte 和 MultiByteToWideChar 实现。但是如果调用标准库函数
的话,在 Linux 下也是有效的。调用标准库函数,首先必须包含 locale.h 并调用 setlocale(LC_ALL, "") 后才能正确转换。Windows 下的 Multi-byte 是 ANSI 编码的,Wide charactor 是 Unicode (UTF-16) 编码,而 Linux 下的 Multi-byte 是 UTF-8 编码的,Wide charactor 是 Unicode (UTF-32) 编码。\r\n\r\n#include \r\n#include \r\n#include \r\n\r\nint main(void)\r\n{\r\nchar str[12]\r\nwchar_t wstr[] = { 0x52B3, 0x788C, 0 }\r\nsetlocale(LC_ALL, "")\r\nwcstombs(str, wstr, sizeof(str)/sizeof(char))\r\nprintf("%s", str)\r\nreturn 0\r\n}
对,有。
#define _CONVERSION_USES_THREAD_LOCALE
#include <atlbase.h>
#include <atlconv.h>
#include <stdio.h>
#include <string.h>
int main()
{
USES_CONVERSION
_acp = CP_ACP
char buf[3] = {0}
buf[0] = getchar()
buf[1] = getchar()
wchar_t tmpbuf[2] = {0}
tmpbuf[0] = A2W(buf)[0]
_acp = CP_UTF8
char utf8buf[4]
strcpy(utf8buf, W2A(tmpbuf))
int i = 0
while(utf8buf[i] != 0)
{
printf("%02x ", (unsigned char)utf8buf[i])
++i
}
return 0
}
如果不是VC6.0而是新的VC的话是新的写法。
你可以输入一个日进去看看
《C语言将UTF-8编码的txt文件改成ANSI编码》百度网盘免费下载
链接: https://pan.baidu.com/s/1Ck9uw8pwDivK5DWadL0roA
提取码: id61
C语言将UTF-8编码的txt文件改成ANSI编码