I was using the std::fstream library, and I found out that it was failing to write. Turns out, it was an mdash.
wchar_t mdash[] = { 0x2014, 0x0000 };
std::wfstream os("filename.txt", std::ios_base::out| std::ios_base::trunc);
os << mdash;
assert(!os.bad()); // fails
I'm not in control of what stuff I'm going to dump to the file, so I needed a way to properly write out the file without crapping out. So I wrote this function based on this answer.
void set_locale_on_stream(std::wfstream &os)
{
char* locale = setlocale(LC_ALL, "English"); // Get the CRT's current locale.
std::locale lollocale(locale);
setlocale(LC_ALL, locale); // Restore the CRT.
os.imbue(lollocale); // Now set the std::wcout to have the locale that we got from the CRT.
}
This worked, except now I've got my numbers getting grouping separators added to them, and they are hex, making it totally useless!
Is there a way to stop that from happening?