为什么VC++ 2010使用char缓冲区而不是wchar_t缓冲区来表示basic_filebuf

发布于 2024-10-02 21:56:46 字数 452 浏览 3 评论 0原文

对我来说非常非常奇怪的是 VC++ 文档说:(位于: http://msdn.microsoft.com/en-us/library/tzf8k3z8(VS.90).aspx)

“basic_filebuf 类型的对象是使用 char * 类型的内部缓冲区创建的,无论 char_type 是什么由类型参数 Elem 指定,这意味着 Unicode 字符串(包含 wchar_t 字符)在写入内部缓冲区之前将被转换为 ANSI 字符串(包含 char 字符)。要在缓冲区中存储 Unicode 字符串,请创建一个新的。 wchar_t 类型的缓冲区并使用 basic_streambuf::pubsetbuf() 方法设置它。要查看演示此行为的示例,请参见下文。”

为什么?

It is very very strange to me that the VC++ docs says: (at: http://msdn.microsoft.com/en-us/library/tzf8k3z8(VS.90).aspx)

"Objects of type basic_filebuf are created with an internal buffer of type char * regardless of the char_type specified by the type parameter Elem. This means that a Unicode string (containing wchar_t characters) will be converted to an ANSI string (containing char characters) before it is written to the internal buffer. To store Unicode strings in the buffer, create a new buffer of type wchar_t and set it using the basic_streambuf::pubsetbuf() method. To see an example that demonstrates this behavior, see below."

Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖彼岸 2024-10-09 21:56:46

这只是一个猜测,但可能会用这种方式来处理常见情况(至少在 Windows 上),其中程序的内部结构是 wchar_t (16 位 Unicode 字符),但它输出的大多数/所有文本文件都是 8 位 ANSI。

大多数文本文件看起来仍然是 ANSI 的,除非确实需要,而且许多程序无法正确处理 Unicode 文本文件。

我想知道它是否真的转换为 ANSI 字符串或 UTF-8 字符串...

This is only a guess but it may be this way to handle the common case (at least on Windows) where the program's internals are wchar_t (16-bit Unicode characters) but most/all text files it outputs are 8-bit ANSI.

Most text files still seem to be ANSI unless they really need to be otherwise, and many programs cannot cope properly with Unicode text files.

I wonder if it's really an ANSI string or a UTF-8 string that it converts to...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文