宽字串问题...... [英] wide string problem ...

查看:68
本文介绍了宽字串问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在写一个将长

值转换为宽字符串的函数时遇到了重大问题!我很可能会在

圈子中走动,而现在却没有看到木头的树木但是我很沮丧

就是这样。

我的功能如下:


std :: wstring CReportCreator :: SetEmpricalDefaults(const udtLONG&

udtValue)

{

wstring ret = L"" ;;

ret = Utilities :: LongToStdWString(udtValue.lngValue);

return ret ;


}

LongToStdWString()在其他地方使用,工作正常。


我的电话是:


wstring strOut = SetEmpricalDefaults(300L);


然后:


WCHAR xml [255 ];

wsprintf(xml,L"< X>< a = \"%s \" />< / X>",strOut);


wsprintf抛出一个标量删除析构函数异常。


当我调试strOut show为* 300时。


有没有人知道''''代表什么300的开头?

有没有人知道一个函数会从

返回一个unicode字符串?到目前为止我已经尝试过stringstreams和_ltow,但总是在300前面得到

*而且wsprintf引发异常...


非常感谢

解决方案

3月12日下午5:27,SteveB < s ... @ thebretts.co.ukwrote:





我写的主要问题将长

值转换为宽字符串的函数!我很可能会在

圈子中走动,而现在却没有看到木头的树木但是我很沮丧

就是这样。

我的功能如下:


std :: wstring CReportCreator :: SetEmpricalDefaults(const udtLONG&

udtValue)

{

wstring ret = L"" ;;

ret = Utilities :: LongToStdWString(udtValue.lngValue);

return ret ;


}


LongToStdWString()在别处使用,工作正常。


我的电话是这样的:


wstring strOut = SetEmpricalDefaults(300L);


然后:


WCHAR xml [255];

wsprintf(xml,L"< X>< a = \"%s \" />< / X>" ;,strOut );



wsprintf(xml,L"< X>< a = \"%s \" />< / X>" ,strOut.data()); //应该是

这个?


>

wsprintf抛出一个标量删除析构函数异常。


当我调试strOut时显示为* 300。


有没有人知道'*''代表300开头的代价?


有没有人知道一个函数将从

a long返回一个unicode字符串?到目前为止我已经尝试过stringstreams和_ltow,但总是在300前面得到

*而且wsprintf引发异常...


非常感谢



* SteveB:




我在编写一个将长

值转换为宽字符串的函数时遇到了重大问题!我很可能会在

圈子中走动,而现在却没有看到木头的树木但是我很沮丧

就是这样。

我的功能如下:


std :: wstring CReportCreator :: SetEmpricalDefaults(const udtLONG&

udtValue)

{

wstring ret = L"" ;;

ret = Utilities :: LongToStdWString(udtValue.lngValue);

return ret ;



}


只是一个风格问题,但要做到这一点


{

返回Utilities :: LongToStdWString(udtValue.lngValue);

}


LongToStdWString ()在别处使用,工作正常。



如果你这样说。


我的电话是:


wstring strOut = SetEmpricalDefaults(300L);


然后:


WCHAR xml [255];

wsprintf(xml,L"< X>< a = \"%s \" />< / X>",strOut);


wsprintf抛出标量删除析构函数异常。



是的,将非POD类类型对象传递给...是未定义的行为。


目前还不清楚为什么要将字符串复制到固定大小的缓冲区。


当我调试strOut显示为* 300时。


有没有人知道'*''在300开头代表什么?



如果你的调试器不是文本字符串值的一部分,则取决于你的调试器。


任何人都知道一个函数将从

a long返回一个unicode字符串?



您在上面说过,LongToStdWString()用于其他地方且工作正常。


so我已经尝试过stringstreams



缺少g ++ for Windows中的宽字符串流支持;也许

'你正在使用的编译器?


和_ltow


非标准。


但总是得到300
前面的*


大部分无关紧要。


和wsprintf抛出异常...



如果这是上面显示的代码,请参见上文。


-

答:因为它弄乱了订单人们通常会阅读文字。

问:为什么这么糟糕?

A:热门帖子。

问:什么是usenet和电子邮件中最烦人的事情是什么?


3月12日,09:59,mimi < cainiaodelixi ... @ gmail.comwrote:


3月12日下午5:27,SteveB < s ... @ thebretts.co.ukwrote:


Hi


我在编写一个将长

值转换为宽字符串的函数时遇到了重大问题!我很可能会在

圈内走动,而现在却没有看到木头的树木,但我很沮丧

就是这样。


我的函数如下所示:


std :: wstring CReportCreator :: SetEmpricalDefaults(const udtLONG&

udtValue)

{

wstring ret = L"" ;;

ret = Utilities :: LongToStdWString(udtValue.lngValue);

return ret;


}


LongToStdWString()在其他地方使用并且工作正常。


我的调用是:


wstring strOut = SetEmpricalDefaults( 300L);


然后:


WCHAR xml [255];

wsprintf(xml,L"< X>< a = \"%s \" />< / X>",strOut);



wsprintf(xml,L"< X>< a = \"%s \" />< / X>" ,strOut.data()); //应该是

这个?



wsprintf抛出标量删除析构函数异常。


当我调试strOut时显示为* 300。


有没有人知道'*''在300开头代表什么?


有没有人知道一个函数会从

返回一个unicode字符串?到目前为止我已经尝试过stringstreams和_ltow,但总是在300前面得到

*而wsprintf抛出异常...


非常感谢 - 隐藏引用的文字 -



- 显示引用的文字 - 隐藏引用的文字 -


- 显示引用的文字 -



非常感谢


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;

}
LongToStdWString() is used elsewhere and works ok.

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.

when i debug strOut show as "*300".

does anyone know what the ''*'' represents at the beginning of the 300 ?

does anyone know of a function that will return a unicode string from
a long ? so far i''ve tried stringstreams and _ltow but always get the
* in front of the 300 and wsprintf throws an exception ...

many thanks

解决方案

On Mar 12, 5:27 pm, "SteveB" <s...@thebretts.co.ukwrote:

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;

}

LongToStdWString() is used elsewhere and works ok.

My call is this:

wstring strOut = SetEmpricalDefaults(300L);

and then:

WCHAR xml[255];
wsprintf(xml, L"<X><a=\"%s\" /></X>", strOut);

wsprintf(xml, L"<X><a=\"%s\" /></X>", strOut.data()); //Should be
this?

>
wsprintf throws a scalar deleting desctructor exception.

when i debug strOut show as "*300".

does anyone know what the ''*'' represents at the beginning of the 300 ?

does anyone know of a function that will return a unicode string from
a long ? so far i''ve tried stringstreams and _ltow but always get the
* in front of the 300 and wsprintf throws an exception ...

many thanks



* 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?


On 12 Mar, 09:59, "mimi" <cainiaodelixi...@gmail.comwrote:

On Mar 12, 5:27 pm, "SteveB" <s...@thebretts.co.ukwrote:

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;

}

LongToStdWString() is used elsewhere and works ok.

My call is this:

wstring strOut = SetEmpricalDefaults(300L);

and then:

WCHAR xml[255];
wsprintf(xml, L"<X><a=\"%s\" /></X>", strOut);


wsprintf(xml, L"<X><a=\"%s\" /></X>", strOut.data()); //Should be
this?


wsprintf throws a scalar deleting desctructor exception.

when i debug strOut show as "*300".

does anyone know what the ''*'' represents at the beginning of the 300 ?

does anyone know of a function that will return a unicode string from
a long ? so far i''ve tried stringstreams and _ltow but always get the
* in front of the 300 and wsprintf throws an exception ...

many thanks- Hide quoted text -


- Show quoted text -- Hide quoted text -

- Show quoted text -

many thanks


这篇关于宽字串问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆