Great.. Now there is no text corruption.
"Ted" <ted@t--x.org> wrote in message
news:OHWTYz1FFHA.3928@TK2MSFTNGP15.phx.gbl...
> To get it to work with those characters, you must use binary and follow
> the
> advice in the links that I gave you (e.g. write BOM)
>
> wofstream fout;
> fout.imbue( locale(locale::classic(), new NullCodecvt) );
> fout.open(sPath.c_str(), ios::out|ios::binary);
> fout << wchar_t(0xFEFF);
>
> Ted.
>
> "TomTom" <no_spam@nospamfordiscussion.com> wrote in message
> news:O0M4awyFFHA.2156@TK2MSFTNGP09.phx.gbl...
>> Thanks, Ted. I could make it work for Western European characters such as
>> "ABC", but I see nothing for the non-European chars, such as Japanese. I
>> saved the NotePad as Unicode, but then I see garbage instead of the
> Japanese
>> chars.
>>
>> The code looks like this.
>>
>> void WriteToLog(BSTR myText)
>> {
>> wstring convertedText = wstring(uiText, lstrlen(myText));
>> char logFileName[] = "myLog.txt";
>> wofstream logFile(logFileName, ios::app);
>> logFile << convertedText.c_str() << L"\n";
>> logFile.close();
>>
>> }
>>
>>
>>
>>
>> "Ted" <ted@t--x.org> wrote in message
>> news:%23B1NpswFFHA.1476@TK2MSFTNGP09.phx.gbl...
>> > P.S. and don't forget the BOM (byte order mark) - mentioned in one of
> the
>> > comments in the codeproject article.
>> >
>> > Ted.
>> >
>> > "Ted" <ted@t--x.org> wrote in message
>> > news:uHrySlwFFHA.2296@TK2MSFTNGP15.phx.gbl...
>> >> use wofstream and read
>> >>
http://www.codeproject.com/vcpp/stl/upgradingstlappstounicode.asp >> >>
>> >> and
>> >>
>> >>
>> >
>
http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=7cqqst%24p64%40bgtnsc03.worldnet.att.net
>> >>
>> >> Ted.
>> >>
>> >> "TomTom" <no_spam@nospamfordiscussion.com> wrote in message
>> >> news:eL50jJuFFHA.2180@TK2MSFTNGP10.phx.gbl...
>> >> > Hi,
>> >> >
>> >> > I have a very simple program below. I am trying to output Unicode
>> >> characters
>> >> > in a file.
>> >> >
>> >> > -----------
>> >> >
>> >> > ofstream logFile("myLog.txt");
>> >> > logFile << L"ABC"; // In the actual scenario, the characters
> will
>> >> > include multinational characters.
>> >> >
>> >> > ---------
>> >> >
>> >> > After the program is run, the myLog.txt includes:
>> >> >
>> >> > 004980DC
>> >> >
>> >> > Is there a Unicode counterpart of ofstream? Or do I need to somehow
>> >> convert
>> >> > the numbers above to actual characters?
>> >> >
>> >> > By the way, MFC cannot be used in my environment.
>> >> >
>> >> > Thanks much,
>> >> > TomTom
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>