问题
This line.
UpdateData(true);
if( m_OldPassword.Compare(d.pass) && m_NewPassword.Compare(m_ConfirmPassword) )
m_OldPassword, m_NewPassword, m_ConfirmPassword
is variable i added from EditControl
m_OldPassword.Compare(d.pass)
Result =true (tested)
m_NewPassword.Compare(m_ConfirmPassword)
Result = false.
IMPLEMENT_DYNAMIC(ChangePassword, CDialog)
ChangePassword::ChangePassword(CWnd* pParent /*=NULL*/)
: CDialog(ChangePassword::IDD, pParent)
, m_OldPassword(_T(""))
, m_NewPassword(_T(""))
, m_ConfirmPassword(_T(""))
{
}
I dont know what's happen. I sure my input(new, confirm) is right.
回答1:
You need to do
if( m_OldPassword.Compare(d.pass)==0 && m_NewPassword.Compare(m_ConfirmPassword)==0 )
if you are comparing two Cstring say abc
and xyz
if abc equal to the string xyz it will return 0
if abc greater than the string xyz it will return 1
if abc less than the string xyz it will return -1
来源:https://stackoverflow.com/questions/27273176/why-i-cant-compare-cstring-in-mfc