if(str1 != NULL)
{
AfxMessageBox("str1為空");
}
esle
{
AfxMessageBox("str1不為空");
}
因為str1它是壹個CString對象,而不是壹個指針,將壹個對象和NULL指針做比較顯然是不合適的。
有朋友要問,出了IsEmpty()函數,還有沒有其他方法判斷CString字符串為空呢?有,我們介紹壹個效率較低的方法:
CString str1 = "VC源碼網";
if (x != "")
{
AfxMessageBox("str1不為空");
}
else
{
AfxMessageBox("str1為空");
}