坐等:C++求高手指导一个有关问题

坐等:C++求高手指导一个问题
#include<iostream>
using namespace std;
int main()
{
char *strTemp=NULL;
char bufDest[20]={0};
int i=4;
strTemp=bufDest;
    char *strSrc="hello";
strTemp=strcpy(bufDest,strSrc);
if(strTemp==strSrc)
cout<<i<<endl;
return 0;
}在调试到if语句的时候出现问题,没有执行cout,而是直接return了,这是为什么

------解决方案--------------------
strTemp和strSrc两个指针比较显然是不相等的,要判断字符串是否相等应该用strcmp函数。

引用:
#include<iostream>
using namespace std;
int main()
{
char *strTemp=NULL;
char bufDest[20]={0};
int i=4;
strTemp=bufDest;
    char *strSrc="hello";
strTemp=strcpy(bufDest,strSrc);
if(strTemp==strSrc)
cout<<i<<endl;
return 0;
}在调试到if语句的时候出现问题,没有执行cout,而是直接return了,这是为什么

------解决方案--------------------

//  if(strTemp==strSrc)   // 你这里比较的只是地址而已!所以肯定不一样的,
    if(strncmp(strTemp, strSrc) == 0) // 字符串不能直接用等于号的来比较内容的
        cout<<i<<endl;
    return 0;