Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > stl, iostream a...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 9779 of 9909
Post > Topic >>

stl, iostream and wchar_t

by kmmx <kmmx@[EMAIL PROTECTED] > Jul 10, 2008 at 02:15 PM

{ 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! ]
 




 5 Posts in Topic:
stl, iostream and wchar_t
kmmx <kmmx@[EMAIL PROT  2008-07-10 14:15:56 
Re: stl, iostream and wchar_t
Alberto Ganesh Barbati &l  2008-07-10 19:38:05 
Re: stl, iostream and wchar_t
Oncaphillis <oncaphill  2008-07-10 20:28:08 
Re: stl, iostream and wchar_t
Vaclav Haisman <v.hais  2008-07-10 20:28:07 
Re: stl, iostream and wchar_t
Ulrich Eckhardt <eckha  2008-07-11 14:18:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 12:58:07 CDT 2008.