gpt4 book ai didi

c - C中标准输出的方向是什么

转载 作者:太空宇宙 更新时间:2023-11-04 00:06:57 25 4
gpt4 key购买 nike

GNU C manual说:

Being able to use the same stream for wide and normal operations comes with a restriction: a stream can be used either for wide operations or for normal operations.

[...]

It is important to never mix the use of wide and not wide operations on a stream. There are no diagnostics issued. The application behavior will simply be strange or the application will simply crash. The fwide function can help avoiding this.

我已经在 vs2012 上试过了,一个 printf 紧接着一个 wprintf,这个简单的程序可以正常工作。

那么我的问题是,手册是什么意思?何时以及为什么我们应该使用 fwide 函数?

最佳答案

manual更完整地说:

Being able to use the same stream for wide and normal operations comes with a restriction: a stream can be used either for wide operations or for normal operations. Once it is decided there is no way back. Only a call to freopen or freopen64 can reset the orientation. The orientation can be decided in three ways:

  • If any of the normal character functions is used (this includes the fread and fwrite functions) the stream is marked as not wide oriented.
  • If any of the wide character functions is used the stream is marked as wide oriented.
  • The fwide function can be used to set the orientation either way.

It is important to never mix the use of wide and not wide operations on a stream. There are no diagnostics issued. The application behavior will simply be strange or the application will simply crash. The fwide function can help avoiding this.

请注意,Microsoft 文档说他们的 fwide()“未实现”(这是一个空操作)并且“不符合标准”。

我对这一切的理解是,使用 glibc 的程序不得在不重新打开单个流的情况下同时使用窄字符函数和宽字符函数。也许在 Microsoft 平台上没有这样的限制;甚至其他 libc 实现可能更灵活。

关于c - C中标准输出的方向是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19834506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com