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::exceptiondoes not supportwchar_tstrings, so you will have to either convert yourwchar_tbuffer into a separatecharbuffer, or do not switch to awchar_tbuffer to begin with assprintf()does support formatting Unicode input via its%Sand%lsformatting specifiers, eg: