Hi,
I wrote some code, aiming at loading a text
files in UNICODE:
#include
<iostream>
#include
<fstream>
#include
<sstream>
using namespace
std;
int _tmain(int /*argc*/,
_TCHAR* /*argv[]*/)
{
wstring
szresource;
wstringstream
strstm;
wifstream
file;
file.open(L"E:\\Page1.xml");
while(!file.fail()
&&
!file.eof())
{
file
>> szresource;
wcout
<< szresource.c_str() <<
endl;
strstm
<< szresource;
}
//
other operation
return
0;
}
The file "Page1.xml" is not a standard XML
file, but just a normal text. However, the wcout function just printed
out the first character stored in szresource, and after the
while loop, strstm had only
the first character in its stream too.
I debugged the code and found it quite strange.
The text in Page1.xml contained only a word:
Dialog
And I thought since it was handled by wchar_t,
it should be like
44 00
69 00 61 00 6c 00 6f 00 67
00
However, in the corresponding memory map, it
was
44 00
00 00 69 00 00 00 61 00 00 00 6c 00 00 00 6f 00
00 00 67 00 00 00
I was really confused...is there
anybody could help? by the way, the
solution was built using unicode char set by
default.
Thanks a lot!
Get Busy Living, or Get Busy Dying