Reputation: 5226
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]"
?
Upvotes: 2
Views: 3676
Reputation: 121991
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
.
Upvotes: 7
Reputation: 399889
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.
Upvotes: 5