vs_u8前缀
1、ZC: 个人测试下来,VS2015开始 支持 u8前缀。
2、What's New for Visual C++ in Visual Studio 2015 https://msdn.microsoft.com/zh-cn/library/hh409293.aspx
新字符类型和 Unicode 文本 现在支持 UTF-8、UTF-16 和 UTF-32 中的字符文本和字符串,并引入了新字符类型 char16_t 和 char32_t。 字符文本可以具有前缀 u8 (UTF-8)、u (UTF-16) 或 U (UTF-32)(如 U'a),而字符串还可以使用原始字符串等效项 u8R(UTF-8 原始字符串)、uR(UTF-16 原始字符串)或 UR(UTF-32 原始字符串)作为前缀。 通用字符名可以在 unicode 文本中随意使用(如 u'\u00EF'、u8"\u00EF is i" 和 u"\U000000ef is I")。 (C++11)
3、测试
3.1、vs2015x86 Enterprise Update1 (Thinkpad E40 用vs2015,确实比较卡了...)
#include "stdafx.h" #include <windows.h> #include <string> #include <iostream> using namespace std; int main() { //char* pc = u8"AA"; //u8""; char* pc = "退出"; printf("%s\n", pc); char *p = pc; while (p[0] != 0) { printf("%02X ", ((int)p[0])&0xFF); p ++; } printf("\n\n"); std::string str = u8"退出"; printf("%s\n", str.c_str()); for (int i = 0; i < str.length(); i++) { char cc = str.at(i); printf("%02X ", ((int)cc) & 0xFF); } printf("\n"); cout << str << endl; ::MessageBoxA(0, pc, str.c_str(), 0); system("pause"); return 0; }
3.1.1、运行结果输出
3.1.2、疑问:虽然 编码是对的(参看下面的java代码),但是为何显示是乱码??(printf 和 cout 的问题??)
3.2、java测试代码:
package str; public class TstrTest { public static void main(String[] args) throws Exception { String str = "退出"; byte[] bytesGBK = str.getBytes("gbk"); for (int i=0; i<bytesGBK.length; i++) System.out.print(String.format("%02X ", bytesGBK[i])); System.out.println(); byte[] bytesUTF8 = str.getBytes("utf-8"); for (int i=0; i<bytesUTF8.length; i++) System.out.print(String.format("%02X ", bytesUTF8[i])); } }
3.2.1、运行输出:
4、
5、
分类:
VC
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从“看懂世界”到“改造世界”:AI发展的四个阶段你了解了吗?
· 协程本质是函数加状态机——零基础深入浅出 C++20 协程
· 编码之道,道心破碎。
· 记一次 .NET 某发证机系统 崩溃分析
· 微服务架构学习与思考:SOA架构与微服务架构对比分析
· 历时半年,我将一个大型asp.net的零代码快速开发平台转成了java
· C#实现语音预处理:降噪、静音检测、自动增益(附Demo源码)
· 推荐五大AI+MCP自动化测试工具!
· 记一次 .NET 某无语的电商采集系统 CPU爆高分析
· Spring Boot 启动优化实践