Consider this sample program:
#include
#include
#include
int main()
{
std::string narrowstr = \"narrow\";
You need to do:
wprintf(L"3 %hs \n", narrowstr.c_str());
wprintf(L"4 %s \n", widestr.c_str());
Why? Because for printf
, %s says narrow-char-string. For wprintf
, %ls says wide.
But, for wprintf
, %s implies wide, %ls would mean wide itself. %hs would mean narrow (for both). For printf
, %s, in this manner would simply mean %hs
On VC++/Windows, %S
(capital S), would reverse the effect. Therfore for printf("%S")
it would mean wide, and wprintf("%S")
would mean narrow. This is useful for _tprintf
.