Re: wide string problem ...
* SteveB:
Hi
I'm having major problems writing a function that converts a long
value into a wide string !!! I'm more than likely going round in
circles and not seeing the wood for the trees now but am frustreated
just the same.
My function looks like this:
std::wstring CReportCreator::SetEmpricalDefaults(const udtLONG&
udtValue)
{
wstring ret = L"";
ret = Utilities::LongToStdWString(udtValue.lngValue);
return ret;
}
Just a style issue, but make that
{
return Utilities::LongToStdWString(udtValue.lngValue);
}
LongToStdWString() is used elsewhere and works ok.
If you say so.
My call is this:
wstring strOut = SetEmpricalDefaults(300L);
and then:
WCHAR xml[255];
wsprintf(xml, L"<X><a=\"%s\" /></X>", strOut);
wsprintf throws a scalar deleting desctructor exception.
Yes, passing a non-POD class type object to "..." is Undefined Behavior.
It's unclear why you're trying to copy the string to a fixed size buffer.
when i debug strOut show as "*300".
does anyone know what the '*' represents at the beginning of the 300 ?
Depends on your debugger if it's not part of the textual string value.
does anyone know of a function that will return a unicode string from
a long ?
You stated above, "LongToStdWString() is used elsewhere and works ok".
so far i've tried stringstreams
The wide string stream support in g++ for Windows is lacking; perhaps
that's the compiler you're using?
and _ltow
Non-standard.
but always get the * in front of the 300
Mostly irrelevant.
and wsprintf throws an exception ...
If this is from the code shown above, then see above.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?