首页 > 其他 > 详细

编码格式(未完待续......)

时间:2015-04-04 12:10:29      阅读:207      评论:0      收藏:0      [点我收藏+]
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  }

 

编码格式(未完待续......)

原文:http://www.cnblogs.com/nchxmoon/p/4391722.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!