convert unicode to char(将 unicode 转换为 char)
问题描述
如何在 char* 或 char* const
="nofollow">embarcadero c++ ?
How can I convert a Unicode string to a char*
or char* const
in embarcadero c++ ?
推荐答案
Unicode 字符串"确实不够具体,无法知道您的源数据是什么,但您可能是指UTF-16 字符串存储为 wchar_t 数组",因为这是大多数不知道正确术语的人使用的.
"Unicode string" really isn't specific enough to know what your source data is, but you probably mean 'UTF-16 string stored as wchar_t array' since that's what most people who don't know the correct terminology use.
"char*" 也不足以知道你想要定位什么,尽管也许 "embarcadero" 有一些约定.除非您另有说明,否则我将假设您需要 UTF-8 数据.
"char*" also isn't enough to know what you want to target, although maybe "embarcadero" has some convention. I'll just assume you want UTF-8 data unless you mention otherwise.
另外,我将把我的例子限制在 VS2010 中的工作
Also I'll limit my example to what works in VS2010
// your "Unicode" string
wchar_t const * utf16_string = L"Hello, World!";
// #include <codecvt>
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t> convert;
std::string utf8_string = convert.to_bytes(utf16_string);
这假设 wchar_t 字符串是 UTF-16,就像在 Windows 上的情况一样,否则是可移植代码.
This assumes that wchar_t strings are UTF-16, as is the case on Windows, but otherwise is portable code.
这篇关于将 unicode 转换为 char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 unicode 转换为 char


基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01