混淆关于C ++的std :: wstring,UTF-16,UTF-8和在Windows GUI中显示字符串 [英] Confused about C++'s std::wstring, UTF-16, UTF-8 and displaying strings in a windows GUI
问题描述
我正在开发一个只有英语的C ++程序在Windows中,我们被告知总是使用std :: wstring,但似乎没有人在团队中真正有很多的了解以外。
I'm working on a english only C++ program for Windows where we were told "always use std::wstring", but it seems like nobody on the team really has much of an understanding beyond that.
我已经阅读过题为std :: wstring VS std :: string的问题。这非常有帮助,但我仍然不太明白如何将所有信息应用到我的问题。
I already read the question titled "std::wstring VS std::string. It was very helpful, but I still don't quite understand how to apply all of that information to my problem.
我正在工作的程序在Windows GUI中显示数据,该数据以XML格式保存,我们经常使用XSLT将该XML转换为HTML或XSL:FO以用于报告。
The program I'm working on displays data in a Windows GUI. That data is persisted as XML. We often transform that XML using XSLT into HTML or XSL:FO for reporting purposes.
我已经阅读的是,HTML应该编码为UTF-8。我对GUI开发了解很少,但我读到的一点表明GUI东西都是基于UTF-16编码的字符串。
My feeling based on what I have read is that the HTML should be encoded as UTF-8. I know very little about GUI development, but the little bit I have read indicates that the GUI stuff is all based on UTF-16 encoded strings.
我想知道这离开了我们说我们决定所有的持久化数据应该是UTF-8编码的XML。这是否意味着为了在UI组件中显示持久化数据,我应该真正执行某种显式的UTF-8到UTF-16转码过程?
I'm trying to understand where this leaves me. Say we decide that all of our persisted data should be UTF-8 encoded XML. Does this mean that in order to display persisted data in a UI component, I should really be performing some sort of explicit UTF-8 to UTF-16 transcoding process?
I
推荐答案
Windows NT4以上的版本可能有疑问我的解释可能使用澄清,所以我会尝试提供。是基于Unicode编码的字符串,是的。早期版本基于UCS-2,它是前身或UTF-16,因此不支持UTF-16的所有字符。后来的版本基于UTF-16。不是所有的操作系统都基于UTF-16 / UCS-2。例如,* nix系统基于UTF-8。
Windows from NT4 onwards is based on Unicode encoded strings, yes. Early versions were based on UCS-2, which is the predecessor or UTF-16, and thus does not support all of the characters that UTF-16 does. Later versions are based on UTF-16. Not all OSes are based on UTF-16/UCS-2, though. *nix systems, for instance, are based on UTF-8 instead.
UTF-8是永久存储数据的一个很好的选择。它是在所有Unicode环境中普遍支持的编码,它是数据大小和无损数据兼容性之间的良好平衡。
UTF-8 is a very good choice for storing data persistently. It is a universally supported encoding in all Unicode environments, and it is a good balance between data size and loss-less data compatibility.
是的,您必须解析XML,从中提取必要的信息,并将其解码并转换为UI可以使用的东西。
Yes, you would have to parse the XML, extract the necessary information from it, and decode and transform it into something the UI can use.
这篇关于混淆关于C ++的std :: wstring,UTF-16,UTF-8和在Windows GUI中显示字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!