1. /u->中文:
将/u后面的16进制转化成10进制,然后赋值给wchar_t/byte;
2. 中文->/u:
3. utf-8:
utf-8 w/o BOM:没有BOM头
utf-8:有3个字节的BOM头,EFBBBF(utf-16头:FFFE),属于unicode编码格式;
1 // 判断是否有BOM头,如果有,则去掉BOW头,然后保存。 2 string strVal; 3 string strPath = CStringHelper::Unicode2ACSII(CProcHelper::GetCurrentProcessPath()); 4 strPath += "\test_utf8.txt"; 5 ifstream ifs(strPath.c_str(), ios::binary); 6 if (ifs.is_open()) 7 { 8 stringstream ss; 9 ss << ifs.rdbuf(); 10 strVal = ss.str(); 11 ifs.close(); 12 13 // 判断是否有头 14 // BOM头:EFBBBF 15 bool b = false; 16 if (0xEF == (byte)strVal.at(0) && 17 0xBB == (byte)strVal.at(1) && 18 0xBF == (byte)strVal.at(2)) 19 { 20 b = true; 21 } 22 23 // 去掉头 24 strVal = strVal.substr(3, strVal.length() - 3); 25 26 string strPath2 = CStringHelper::Unicode2ACSII(CProcHelper::GetCurrentProcessPath()); 27 strPath2 += "\test_utf8_bk.txt"; 28 ofstream ofs(strPath2, ios::binary); 29 if (ofs.is_open()) 30 { 31 ofs << strVal; 32 ofs.close(); 33 } 34 }