首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

C++11 Unicode支持

在C++98中,为了支持Unicode字符,使用wchar_t类型来表示“宽字符”,但并没有严格规定位宽,而是让wchar_t的宽度由编译器实现,因此不同的编译器有着不同的实现方式,GNU C++规定wchar_t为32位,Visual C++规定为16位。由于wchar_t宽度没有一个统规定,导致使用wchar_t的代码在不同平台间移植时,可能出现问题。这一状况在C++11中得到了一定的改善,从此Unicode字符的存储有了统一类型: (1)char16_t:用于存储UTF-16编码的Unicode字符。 (2)char32_t:用于存储UTF-32编码的Unicode字符。 至于UTF-8编码的Unicode数据,C++11还是使用了8bits宽度的char类型数组来表示,而char16_t和char32_t的宽度由其名称可以看出,char16_t为16bits,char32_t为32bits。

03

utf8转换成ansi编码_ansi乱码

int CParserIni::ansi2utf8(const string& ansiStr, string& utf8Str) { int ret = kNoError; do{ //CP_ACP(ANSI字符集) if (ansiStr.empty()) BREAK_WITH_ERROR(kInvalidParameter); //现将本地代码页转换成utf16 int wlen = MultiByteToWideChar(CP_ACP, 0, ansiStr.c_str(), -1, NULL, 0); if (wlen == 0) BREAK_WITH_ERROR(kConvertError); wchar_t *pwBuf = new wchar_t[wlen + 1]; memset(pwBuf, 0, sizeof(wchar_t)*(wlen + 1)); if (MultiByteToWideChar(CP_ACP, 0, ansiStr.c_str(), ansiStr.length(), pwBuf, wlen)==0) BREAK_WITH_ERROR(kConvertError); //再将utf16转换utf8 int len = WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL); if (len == 0) BREAK_WITH_ERROR(kConvertError); char *pBuf = new char[len + 1]; memset(pBuf, 0, len + 1); if (WideCharToMultiByte(CP_UTF8, 0, pwBuf, wlen, pBuf, len, NULL, NULL) == 0) BREAK_WITH_ERROR(kConvertError);

02

扫码

添加站长 进交流群

领取专属 10元无门槛券

手把手带您无忧上云

扫码加入开发者社群

相关资讯

热门标签

活动推荐

    运营活动

    活动名称
    广告关闭
    领券