如何在 C++ 中将 ASCII 字符串转换为 UTF8 字符串?
如何在 C++ 中将 ASCII std::string 转换为 UTF8 (Unicode) std::string?
How to convert an ASCII std::string to an UTF8 (Unicode) std::string in C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
每个 ASCII 字符在 UTF8 中都有相同的表示形式,因此无需转换。
当然,如果输入字符串使用扩展(8 位)ASCII 字符集,则答案会更复杂。
Every ASCII character has the same representation in UTF8, so there is nothing to convert.
Of course, if the input string uses an extended (8-bit) ASCII character set, the answer is more complex.
ASCII 是一种七位编码,同样映射到可以用 ASCII 表示的字符子集的 UTF-8 编码。
简而言之,无事可做。您的 ASCII 字符串已经是有效的 UTF-8。
ASCII is a seven-bit encoding and maps identically onto the UTF-8 encoding of the subset of characters that can be represented in ASCII.
In short, there is nothing to do. Your ASCII string is already valid UTF-8.
我假设 ASCII 指的是 CP1252 或其他 8 位字符集(ASCII 只有 7 位,它直接与 UTF-8 兼容,不需要转换)。标准 C++ 无法做到这一点。您需要 Glibmm、Qt、inov 或 WINAPI 来完成此操作。
I assume that by ASCII you mean CP1252 or other 8 bit character set (ASCII is only 7 bits and it is directly compatible with UTF-8, no conversion required). Standard C++ cannot do it. You need e.g. Glibmm, Qt, iconv or WINAPI to do it.