VC6文本文件:读取类型为UTF-8的文本文件 [英] VC6 Text Files: Reading a text file of type UTF-8

查看:172
本文介绍了VC6文本文件:读取类型为UTF-8的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前使用TChar支持使用Unicode和ANSI读取文本文件,但如何使用UTF-8,ANSI和Unicode读取文本文件.

currently reading a text file using Unicode and ANSI are supported using TChar but how to read a text file using UTF-8,ANSI and Unicode. any samples for reading a text file which supports all encodings.

推荐答案

以二进制模式将文件读取到缓冲区中.然后使用::MultiCharToWideChar将文本转换为所需的格式(使用::WideCharToMultiChar将UTF-16转换为ANSI).

如果文件的编码未知,则可以通过检查BOM(字节顺序标记,与UCS-2/UTF-16和UCS-4/UTF-32文件一起出现,对于UTF-8文件是可选的)来检测到,并且UTF-8有效性检查.如果没有检查匹配,则通常是ANSI编码的文件.有一些库用于ANSI文件的代码页检测.但是,这些检测结果通常是猜测者,它们会返回多个可能的代码页.
Read the file in binary mode into a buffer. Then use ::MultiCharToWideChar to convert the text into the desired format (use ::WideCharToMultiChar to convert UTF-16 to ANSI).

If the encoding of the file is unknown, it can be detected by checking for BOM (Byte Order Mark, present with UCS-2 / UTF-16 and UCS-4 / UTF-32 files, optional with UTF-8 files), and UTF-8 validity checks. If no check matches, it is usually an ANSI encoded file. There are some libraries for codepage detection of ANSI files. However, these detections are guessers that usually return multiple possible codepages.


这篇关于VC6文本文件:读取类型为UTF-8的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆