Why i can't compare CString in MFC

核能气质少年 提交于 2020-01-17 01:23:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!