从注册表接收到的宽数据被截断

wofstream being truncated at wide data received from the registry

本文关键字:数据 注册表      更新时间:2023-10-16

在尝试向文件写入宽字符时,我的wofstream正在截断。

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";

在流中设置了badbit(或其他错误位),使其对之后的任何操作都无效。这可能是在实现定义行为的边界上(特别是对于wchar_t),它只是不会按你想要的方式工作。

最大的错误概率是字符不适合一个2字节的wchar_t,使微软的STL阻塞。