I am trying to write a wstring and wchar_t array to file using wofstream. My wstring is populated with a unicode string I obtained from a registry key name(using RegEnumKeyW). It contains a non-ascii character that is displayed as a square block in the registry. I display the wstring with MessageBoxW to see that it contains the same text as the registry. It does.
However, when I write the wstring to file using wofstream and read it immediately back into another wstring using wifstream, the strings differ. When I look inside the file that was written, it does not contain the proper characters. It has ascii characters where the unicode characters should be. It may be it is downcasting the unicode character to its ascii value and then writing it to file, but this is defintely unexpected given wofstream is designed for wchar_t output.
Do I need to set some locale for it to work right? I have no experience with it, so I am unsure.
I am on Windows XP using MSVC++ 6.0 SP6. I am using the STLport stl because wofstream has a bug with MSVC++.
Thanks for any help you can give.