I have legacy code which I am incrementally porting to Unicode characters in Visual C++ (wchar_t). I've encountered this bit of code that I'd like to convert:
char tmp[256];
sprintf(tmp, "stuff");
throw exception(tmp);
I want to change it to something like this (this gives me a compile error on exception):
wchar_t tmp[256];
swprintf(tmp, "stuff");
throw exception(tmp);
So far I haven't found any document to give me the Unicode equivalent for throw exception, can anyone help me?
Of course I could convert my "tmp" back into a char string, but that just seems silly to have to do that.
std::exception does not support wchar_t strings, so you will have to either convert your wchar_t buffer into a separate char buffer, or do not switch to a wchar_t buffer to begin with as sprintf() does support formatting Unicode input via its %S and %ls formatting specifiers, eg:
char tmp[256];
sprintf(tmp, "%ls", wchar_t data here);
throw exception(tmp);
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