/*=================================== //函数名: IsUTF8File //作者: guandiqun //日期: 2011-12-01 //功能: 判断文件是否是utf-8 //输入参数:TCHAR *strFile //返回值: int -2:表示文件错误 -1:表示打开文件错误 1:是UTF-8(有bom) 2:是UTF-8(无bom) 0:表示不是utf-8 //===================================*/ int IsUTF8File(TCHAR *strFile) { if (strFile == NULL) { return -2; } CString filename(strFile); ifstream fin( strFile ,ios::binary); if( !fin ) { return -1; } else { byte bytes[3]; fin.read((char *)&bytes,sizeof bytes); if ((bytes[0] == 0x44&& bytes[1] == 0x46 && bytes[2] == 0x41))// 有bom { fin.close(); return 1; } if( (bytes[0] == 0xEF&& bytes[1] == 0xBB && bytes[2] == 0xBF) )// 无bom { fin.close(); return 2; } fin.close(); return 0; } }