2

[win 32 C++]

I don't know how to convert float to LPCWSTR/LPWSTR or LPCWSTR <-> LPWSTR

Thanks a lot

2 Answers 2

5
#include <sstream>
...
float f = 45.56;
wstringstream wss;
wss << f;
// wss.str().c_str() returns LPCWSTR
cout << wss.str() << endl;
...
1
2

The native Win32 API doesn't have any functions for printing floating point values, but there's a more recent addition called strsafe which has StringCchPrintf

TCHAR buffer[24];
StringCchPrintf(buffer, sizeof(buffer)/sizeof(TCHAR), "%f", float_value);
1
  • Thanks for your comment but it looks complicated and the simple above does same job :)
    – Tzu ng
    Commented Mar 21, 2010 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.