{ Please note that clc++m moderation is via e-mail, and that this process
most
often will render national characters as garbage. UTF-8 /may/ work. -mod }
Can anyone tell me what the proper method to write a unicode string to
a file is, using streams?
some quick sample code:
typedef std::basic_ofstream<TCHAR, std::char_traits<TCHAR> >
_tofstream;
_tofstream s(_T("filename.txt"));
wchar_t* msg = _T("FOOBAR");
s << msg;
This works fine as long as I only write ANSI characters. As soon as I
write unicode:
wchar_t* msg = _T("??");
we run into problems. See
http://www.codeproject.com/KB/stl/upgradingstlappstounicode.aspx
Okay, so I can use this giant hack mentioned in the article to write a
unicode string. But that just seems "wrong."
I tried opening the file in binary mode as well and writing that way.
But then it seems any time I try to write a wchar_t, the streams
badbit gets set.
Any thoughts?
(I posted this to another C++ group that seems to be spammed to death
with job offers as well.)
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]