当前位置:
首页 >
中文文件名乱码
发布时间:2025/3/21
25
豆豆
用FindNextFile系列api, 遍历目录, 将得到的文件名(unicode)保存在WTL::CString字符串中
使用ofstream o();
USES_CONVERSION;
_acp = CP_UTF8;
o << T2A(LPCTSTR(..)) << endl;
读取时, 使用的是ifstream + char buffer;
逐行读到char buffer中之后, 将文件名部分从utf8转为unicode, 如下: 才能正确打开windows系统下的文件名
wchar_t * u82unicode(char *szU8, wchar_t *dst, int len) {int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, szU8, strlen(szU8), NULL, 0);if(wcsLen >= len) return 0;//转换::MultiByteToWideChar(CP_UTF8, NULL, szU8, strlen(szU8), dst, wcsLen);//最后加上'\0'dst[wcsLen] = '\0';return dst; }
============================================================================================
windows使用unicode
不设置_acp、直接T2A写到文本文件中时, 有些乱码信息会丢掉。!!!【因为_acp没设置对。_acp是USES_CONVERSION宏的变量】。。。。。
总结
- 上一篇: win7 64编译64位boost
- 下一篇: hadoop centos 安装