Convert float/double to wchar_t (unicode)

M

Menny

Hi.
I'm looking for a _gvct replacement for a unicode program.
currently, the _gvct function receives a buffer of char*, which is not
a unicode string.

Any ideas?
 
M

mlimber

Menny said:
Hi.
I'm looking for a _gvct replacement for a unicode program.
currently, the _gvct function receives a buffer of char*, which is not
a unicode string.

Any ideas?

How about using a wstringstream?

#include <string>
#include <sstream>

int main()
{
const float pi = 3.14159;
wstringstream wss;
wss << pi;
const wstring ws( wss.str() );
return 0;
}

Cheers! --M
 
M

Menny

isn't it a bit too heavy?

i've tried this code:
char c_buff[32];//create a regular single-byte buffer
_gcvt(val, digits, c_buff);//doing the regular convertion
mbstowcs(buff, c_buff, digits);//converting from single byte to unicode

but is seems too heavy too.
 
M

mlimber

Menny said:
isn't it a bit too heavy?

i've tried this code:
char c_buff[32];//create a regular single-byte buffer
_gcvt(val, digits, c_buff);//doing the regular convertion
mbstowcs(buff, c_buff, digits);//converting from single byte to unicode

but is seems too heavy too.

That's your call, I suppose, but stringstreams *are* the standard way
to do conversions in C++. Your proposal is C-style, not C++. For more
convenient notation for the stringstreams, you could use Boost's
lexical_cast (http://www.boost.org/libs/conversion/lexical_cast.htm).

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top