将整数转换为CString以在编辑控件中显示时出错 [英] Error when converting integer to CString to display it in a edit control

查看:84
本文介绍了将整数转换为CString以在编辑控件中显示时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将函数返回的整数值设置为一个编辑控件。我用以下方式尝试了它。



I was trying to set an integer value returned by a function to one edit control. and I tried it in the following ways.

CString str;
Int res = 2;
Str.Format("%d", res);
m_conrol.SetWeindowTextw(str);






or

CString str;
Int res = 2;
Str.Format(_T("%d"), res);
m_conrol.SetWeindowTextw(str);



但我得到的错误是这样的


But I am getting an error like this

引用:

.error C2664:'CWnd :: SetWindowTextW':无法将参数1从'char [17]'转换为'LPCTSTR

.error C2664: 'CWnd::SetWindowTextW' : cannot convert parameter 1 from 'char [17]' to 'LPCTSTR



如何更正?

任何人请帮助。


How can I correct this?
Anybody please help.

推荐答案

不要使用 SetWindowTextW ,因为其余的你的代码是MBCS / Unicode可切换的。使用base SetWindowText (不带 W )并让编译器生成正确的版本。所以你的代码应该是:

Don't use SetWindowTextW, since the rest of your code is MBCS/Unicode switchable. Use the base SetWindowText (without the W) and let the compiler generate the correct version. So your code should be:
CString str;
Int res = 2;
Str.Format(_T("%d"), res);
m_conrol.SetWindowText(str);



另请注意使用 _T()宏,你应该将它用于所有字符串常量。


Note also the use of the _T() macro, you should use it for all string constants.


这篇关于将整数转换为CString以在编辑控件中显示时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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