I'm converting the formatted strings to a single wchar_t*. When I have a stream containing %s, vswprintf somehow doesn't form a expected wchar_t* out of that formatted string. This is happening only in Windows(VS 2008) but works well in Mac (XCode 3.2.6)
For example,
my formatting function:
void widePrint(const wchar_t* fmt, ...) {
va_list args;
va_start(args, fmt);
wchar_t buf[32*1024] = {0};
vswprintf(buf,(32*1024 - 1),fmt, args);
...//Prints buf
...
}
this doesn't work in Windows but works well in Mac
std::string normalStr = "test Str";
std::wstring wideStr = L"wide test Str";
widePrint("Normal One: %s and Wide One: %ls", normalStr .c_str(), wideStr .c_str());
but if I convert %s to %ls, I mean converting std::string to std::wstring certainly works in Windows also
std::string normalStr = "test Str";
std::wstring normalStrW(normalStr .begin(), normalStr .end());
std::wstring wideStr = L"wide test Str";
widePrint("Normal One: %ls and Wide One: %ls", normalStrW.c_str(), wideStr .c_str());
When I searched online, I can see this Query in Stack Overflow
But even that link doesn't have a solution . How to get rid of this situation where I convert all my std::strings to std::wstrings. Infact convertion is a costly operation .
EDITS: Found out that "%S" -> Capital S , certainly helps to print char* in vswprintf. This below code works.
widePrint("Normal One: %S", normalStr.c_str());
But unfortunately "%S" doesn't work properly in Mac.Is there any workaround for this?