wofstream being truncated at wide data received from the registry

111 views Asked by At

My wofstream is truncating when trying to write wide characters to the file.

my_file << L"something";

wstring foo = //get a value from the registry ..

// foo contains 您好

my_file << foo;

my_file << "stuff that will never be seen";
1

There are 1 answers

0
rubenvb On

The badbit (or other error bit) is being set in your stream, rendering it useless for any operation afterwards. This is probably on the border of implementation defined behavior (especially for wchar_ts). It just won't work the way you want it to.

The largest probability for the error is that the characters don't fit in one 2-byte wchar_t, making Microsoft's STL choke.