I read the "C ++ Cookbook", which had the following snippet:
If you're interested in seeing a real-world example, here is a link to a page on Google books .
Also, I found this SO question , which seems to say that you can mix wcout and cout. Can someone explain to me what this comment is about?
EDIT
From the C ++ standard [27.4.1]:
The mixing operations in the respective wide and narrowband streams follow the same semantics as the mixing operations in the FILE files, as specified in Amendment 1 to ISO C.
From standard C [7.19.2]:
Each thread has an orientation. After the stream is associated with an external file, but before performing any operations on it, the stream has no orientation. Once a wide character I / O function was applied to a stream without orientation, the stream becomes a wide- oriented stream. Likewise, when a byte I / O function has applied to a stream without orientation, the stream becomes a byte-oriented stream. Otherwise, only calling the freopen function or the fwide function can change the orientation of the stream. (A successful call to freopen removes any orientation.)
Byte I / O functions should not be applied to a wide- oriented stream, and wide character I / O functions should not be applied to a byte stream.
So the standard seems to say that you should not mix them. However, I found this quote from this article :
For Visual C ++ 10.0, the fwide function is documented as outstanding. And from a practical point of view, at least at the output level of whole lines, it obviously works great to mix the use of cout and wcout. Therefore, fortunately, Visual C ++, obviously, simply ignores the requirements of the standards and does not support the impractical explicit orientation of the C FILE stream.
And also for GCC, I found this quote from here :
This is a (new) function, not an error, see Libstd C ++ / 11705 and the general search for stream orientation in the C standard (C99, 7.19.2). In a nutshell, you cannot mix byte-oriented and wide-oriented input-output. At the moment, due to an error As indicated in libstd C ++ / 11705, you can get something close to your expectation by calling std :: ios :: sync_with_stdio (false); at the beginning is your program.