问题描述
我不知道为什么不能转换回字符串
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 *''
推荐答案
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)
这篇关于编辑框中的数值数据出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!