VC++ 判断文本文件是否UTF-8编码

来源:互联网 发布:苹果手机评测软件 编辑:程序博客网 时间:2024/04/29 04:33

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″<<endl;
}else
{
cout <<”GB2312″<<endl;
}
}
fin.close();

原创粉丝点击