"Jeffrey Walton" wrote in message
>I'm attempting to write a wstring to a file by way of wofstream. I'm
>getting compression on the stream (I presume it is UTF-8). How/where
>do I invoke an alternate constructotor so that the stream stays wide
>I suspect that it is hidden in a locale, but I don't have much
>experience with them. I also have not been able to locate it in
>Stroustrup: Appendix D: Locales .  does state the following, but
>I do not have section 21.7: "Section 21.7 describes how to change
>locale for a stream; this appendix describes how a locale is
>constructed out of facets and explains the mechanisms through which a
>locale affects its stream."
From my understanding of iostream, locales will not be the answer.
Locales apply to the upper layer of the iostream, which takes
care of converting values to characters. They affect the
choice of the characters used to represent a value, but not
the encoding of these characters.
The internal filebuf or basic_filebuf is the object that will
determine how the in-memory characters are wirtten to a file.
This is the layer (the stream *buffer*) that can define whether
a file is written using UTF8 or another character encoding.
However, the C++ standard does not specify an interface allowing
to select what character encoding is to be used by (w)filebuf.
Your best bet would be to ask your question on a platform-
specific forum, related to the library implementation you use.
A specific wfilebuf (/basic_filebuf) implementation may
allow you to specify the file's enocding style.
Or maybe this is configurable at an OS or C library level.
Worst case, you will still be able to write your own streambuf
layer to write files using the specific encoding you want.
I hope this helps...
Posted On: Wednesday 7th of November 2012 11:42:58 AM
View Complete with Replies