So I have, let's say
float x;
and I have
LPCWSTR message=L"X is";
how can I create a LPCWSTR with the message
"X is [x]"
?
So I have, let's say
float x;
and I have
LPCWSTR message=L"X is";
how can I create a LPCWSTR with the message
"X is [x]"
?
You could use wstringstream:
#include <string>
#include <sstream>
#include <iostream>
int main()
{
float x = 0.1f;
std::wstringstream s;
s << L"X is " << x;
std::wstring ws = s.str();
std::wcout << ws << "\n";
return 0;
}
and create an LPCWSTR from it if required, or just use the std::wstring.
You would use something like wsprintf() or its more modern (and safe) replacement, such as StringCbPrintf().
The point is that you can't just "convert", you need to build the string, character by character, that is the textual representation of the floating-point number.
swprintf which is standard and in recent compilers takes a buffer size parameter so it's also safe.