Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I can not figure out why converting back to a string isn't working


MIDL
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): error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [5]' to 'const wchar_t *'
Posted

You use immediate string constant in the form of literal "%.2f". For C++ this is an array or string of char, but your Format function require wchar_t.

So, prefix the string literal by 'L' to fix it: use L"%.2f".

—SA
 
Share this answer
 
v2
Comments
DrBones69 15-Jun-11 23:54pm    
Thank You, do you have all the answers? Do you think you can connect an RJ-45 cable directly to your brain, so that I may get wired in?
Sergey Alexandrovich Kryukov 16-Jun-11 0:31am    
Thank you, Randy. Your ideas make me worry. Don't do it at home. :-)
--SA
wrap the text in _T(), you're working with wide strings, and giving Format a narrow

m_dbFeeAmt.Format(_T("%.2f"), FeeAmt);     // Error
m_dbPkUpAmt.Format(_T("%.2f"), PickupAmt); // Error


(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)
 
Share this answer
 
v2
Comments
DrBones69 15-Jun-11 23:56pm    
Thanks to all that help me through the rough stages, someday I will return the favors. HOPEFULLY SOON! :)
Sergey Alexandrovich Kryukov 16-Jun-11 0:47am    
This is event better way, my 5.
You should only explain this macro (portable between different pre-processor definitions: support Unicode or not).
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900