![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
use wofstream and read http://www.codeproject.com/vcpp/stl/...stounicode.asp and http://groups.google.co.uk/groups?hl...rldnet.att.net Ted. "TomTom" <no_spam (AT) nospamfordiscussion (DOT) com> wrote in message news:eL50jJuFFHA.2180 (AT) TK2MSFTNGP10 (DOT) 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 |
#4
| |||
| |||
|
|
P.S. and don't forget the BOM (byte order mark) - mentioned in one of the comments in the codeproject article. Ted. "Ted" <ted (AT) t--x (DOT) org> wrote in message news:uHrySlwFFHA.2296 (AT) TK2MSFTNGP15 (DOT) phx.gbl... use wofstream and read http://www.codeproject.com/vcpp/stl/...stounicode.asp and http://groups.google.co.uk/groups?hl...rldnet.att.net Ted. "TomTom" <no_spam (AT) nospamfordiscussion (DOT) com> wrote in message news:eL50jJuFFHA.2180 (AT) TK2MSFTNGP10 (DOT) 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 |
#5
| |||
| |||
|
|
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 (AT) t--x (DOT) org> wrote in message news:%23B1NpswFFHA.1476 (AT) TK2MSFTNGP09 (DOT) 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 (AT) t--x (DOT) org> wrote in message news:uHrySlwFFHA.2296 (AT) TK2MSFTNGP15 (DOT) phx.gbl... use wofstream and read http://www.codeproject.com/vcpp/stl/...stounicode.asp and http://groups.google.co.uk/groups?hl...rldnet.att.net Ted. "TomTom" <no_spam (AT) nospamfordiscussion (DOT) com> wrote in message news:eL50jJuFFHA.2180 (AT) TK2MSFTNGP10 (DOT) 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 |
#6
| |||
| |||
|
|
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: ut|ios::binary);fout << wchar_t(0xFEFF); Ted. "TomTom" <no_spam (AT) nospamfordiscussion (DOT) com> wrote in message news:O0M4awyFFHA.2156 (AT) TK2MSFTNGP09 (DOT) 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 (AT) t--x (DOT) org> wrote in message news:%23B1NpswFFHA.1476 (AT) TK2MSFTNGP09 (DOT) 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 (AT) t--x (DOT) org> wrote in message news:uHrySlwFFHA.2296 (AT) TK2MSFTNGP15 (DOT) phx.gbl... use wofstream and read http://www.codeproject.com/vcpp/stl/...stounicode.asp and http://groups.google.co.uk/groups?hl...rldnet.att.net Ted. "TomTom" <no_spam (AT) nospamfordiscussion (DOT) com> wrote in message news:eL50jJuFFHA.2180 (AT) TK2MSFTNGP10 (DOT) 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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |