我正在使用 vswprintf 从格式化的字符串形成 wchar_t* str 。在该格式化字符串中,要打印 std:string,Mac 接受为 %s,而 Windows VS2008 接受为 %S。例子
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
...
}
...
std::string str = "normal String";
std::wstring strW = L"wideStr";
widePrint(L"str: %S wStr: %ls",str.c_str(), strW.c_str()); //Windows - VS2008
widePrint(L"str: %s wStr: %ls",str.c_str(), strW.c_str()); //Mac - XCode 3.2.6
为什么会有这种行为差异?有没有办法以独立于平台的形式在 vswprintf 中打印 std::string/char* ?