CosminO
CosminO

Reputation: 5226

converting float to LPCWSTR

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

Answers (3)

hmjd
hmjd

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

Indy9000
Indy9000

Reputation: 8861

How about using _vsnwprintf

headers

<wchar.h> <stdarg.h>

reference

Upvotes: 0

unwind
unwind

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

Related Questions