编辑框中的数值数据出现问题 [英] Problem with numerical data in edit box
问题描述
我不知道为什么不能转换回字符串
I can not figure out why converting back to a string isn''t working
m_wndLoanAmt.GetWindowTextW(m_dbLoanAmt);
LoanAmt = _wtof(m_dbLoanAmt);
FeeAmt = LoanAmt*Percent;
PickupAmt = LoanAmt+FeeAmt;
m_dbFeeAmt.Format("%.2f", FeeAmt); // Error
m_dbPkUpAmt.Format("%.2f", PickupAmt); // Error
1> Visual Studio 2010 \ projects \ editctrltest \ editctrltest \ editctrltestview.cpp(112):错误C2664:``void ATL :: CStringT< BaseType,StringTraits> :: Format(const wchar_t *,...)'':无法将参数1从``const char [5]"转换为``const wchar_t *''
1>visual studio 2010\projects\editctrltest\editctrltest\editctrltestview.cpp(112): error C2664: ''void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)'' : cannot convert parameter 1 from ''const char [5]'' to ''const wchar_t *''
推荐答案
您可以使用立即数常量.对于C ++,这是 char
的数组或字符串,但是您的Format函数需要wchar_t
.
因此,请在字符串文字前加上"L"前缀以进行修正:请使用L"%.2f"
.
—SA
You use immediate string constant in the form of literal"%.2f"
. For C++ this is an array or string ofchar
, but your Format function requirewchar_t
.
So, prefix the string literal by ''L'' to fix it: useL"%.2f"
.
—SA
将文本包裹在_T()
中,您正在使用宽字符串,并给
Format
窄了>
wrap the text in_T()
, you''reworking with wide strings, and giving
Format
a narrow
m_dbFeeAmt.Format(_T("%.2f"), FeeAmt); // Error
m_dbPkUpAmt.Format(_T("%.2f"), PickupAmt); // Error
(向SA点头)
_T()
宏非常有用,它会适当替换您正在使用的字符串类型,根据经验,将所有const字符串包装在_T()
中,类似地使用_t*
字符串操纵符(例如<例如,对于printf
是c10>,对于strtok
是_tcstok)
(nods to SA)
The _T()
macro is extremely useful, it substitutes as appropriate, for the string types you''re using, as a rule of thumb, wrap all const strings in _T()
, similarly use the _t*
string manipulators (like _tprintf
for printf
and _tcstok for strtok
, for example)
这篇关于编辑框中的数值数据出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!