标签:
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 }
标签:
原文地址:http://www.cnblogs.com/nchxmoon/p/4391722.html