Intermingling cout and wcout in a Program
The question arises when encountering a warning about mixing cout and wcout in a program. However, further investigation reveals contrasting opinions on the matter.
According to the C Standard [27.4.1], mixing wide and narrow character stream operations should follow the same semantics as mixing such operations on FILEs, as outlined in the ISO C standard's Amendment 1. The C Standard [7.19.2] further underscores that once a stream's orientation is set, whether byte-oriented or wide-oriented, it should not be intermixed with incompatible functions.
However, it is important to note that different compiler implementations may have differing behaviors regarding stream orientation. For example, Visual C apparently disregards the standard's requirements and allows for the intermingling of cout and wcout.
In the case of gcc, a feature known as stream orientation has been implemented. To avoid issues related to stream orientation, it is recommended to call std::ios::sync_with_stdio(false) at the program's inception.
In summary, while the C standard advises against mixing cout and wcout due to stream orientation, certain compiler implementations may have workarounds or different interpretations of stream handling. Referencing the specific compiler's documentation and using recommended practices is crucial for proper implementation.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3