BOOL FileUTF8ToANSI(const char *szUTF8FilePath, const char *szANSIFilePath) const
{
//打开UTF-8文件
ifstream fin(szUTF8FilePath);
fin.seekg(3);//跳过BOM头
//创建要转换ANSI写入的文件
CFile wfile;
if(!wfile.Open(szANSIFilePath, CFile::modeCreate | CFile::modeWrite))
return FALSE;
wfile.SeekToBegin();
string s , str;
const char * pLineBuf =NULL;
while(!fin.eof())
{//没有一次性打开,避免打开太大文件失败 ,逐行读取,当字节大于等于1024时转换一次,以此重复转换直到完成
getline(fin, s);//逐行获取
s += "\r\n";
str += s;
int nStrLen = str.length();
if(nStrLen < 1024)
{//当待转换的字符长度小于1024时,继续读
if(!fin.eof())
continue;
}
pLineBuf = str.c_str();
int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, pLineBuf, nStrLen, NULL, 0);
wchar_t* wszString = new wchar_t[wcsLen + 1];
memset(wszString, 0, si
UTF-8(带BOM)转成ANSI
最新推荐文章于 2020-12-10 20:09:34 发布