c++ - Getting an unexpected error in my MFC application -
i trying access elements of cstring
character character.
i'm getting error in following lines of code:
void ctotaltimecalcdlg::onbnclickedok() { // todo: add control notification handler code here cstring lstring; m_timeget.getwindowtext(lstring); messagebox(lstring[0]); cdialogex::onok(); }
error:
"error 1 error c2664: 'int cwnd::messageboxw(lpctstr,lpctstr,uint)' : cannot convert argument 1 'wchar_t' 'lpctstr'" @ line "messagebox(lstring[0]);"
if want print first character in messagebox
, don't expect convert lpctstr
-> lpcwstr
(unicode) -> const wchar*
wchar_t
.
print whole cstring
, or print first character.
void ctotaltimecalcdlg::onbnclickedok() { // todo: add control notification handler code here cstring lstring; m_timeget.getwindowtext(lstring); if (!lstring.isempty()) messagebox(lstring.left(1)); cdialogex::onok(); }
messagebox accepts lpctstr
parameter.
lpctstr
resolved const wchar_t*
in unicode settings.
cstring::operator[ ]
returns tchar
wchar_t
in unicode.
cstring::operator lpctstr()
see below in code
//you doing this: messagebox(wchar_t); //it wants this: messagebox(wchar_t*); //cstring::left return new cstring messagebox(cstring::left . cstring::operator lpctstr());
Comments
Post a Comment