I have a problem with multibyte char strings. I have simplified my problem as below:
std::wstring str = L"multıbyte test string";
std::wofstream f;
f.open("F:\\dump.txt");
f << str;
f.close();
and the dump file's content is : "mult"
Why does it cuts the remaining part of str altough i have used wstring and wofstream?
Thanks
wofstream
writes out data using the current locale. The default locale probably does not support the multibyte characters.
See question: Unable to write a std::wstring into wofstream
You can get it to output the full string by:
std::locale::global(std::locale(""));
before writing, however you won't get the characters as unicode on windows, since it doesn't support UTF-8 locales natively.
To do that, you should convert it to a std::string using WideCharToMultiByte
, and write it out using regular ofstream
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With