设为首页 加入收藏

TOP

VC++ 判断文本文件是否UTF-8编码
2014-11-23 20:18:02 】 浏览:342
Tags:判断 文本 文件 是否 UTF-8 编码

通过二进制读取文本文件的前三个字节来判断是否是UTF-8编码,以下是最终代码。

string filename = “c:\Default.asp”;
ifstream fin( filename.c_str(),ios::binary);
if( !fin )
{
cout << “打开文件” << filename << “出错” << endl;
//exit(-1);
}
else
{
byte bytes[3];
fin.read((char *)&bytes,sizeof bytes);
if(bytes[0] == 0xEF&& bytes[1] == 0xBB && bytes[2] == 0xBF)
{
cout <<”UTF8″<}else
{
cout <<”GB2312″<}
}
fin.close();

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇一个将自己代码插入IE进程的例子(.. 下一篇VC判断文件是否存在

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目