字符数组strcpy作用的疑问
#include "stdafx.h"#include <iostream.h>
#include <string.h>
class CStrOne
{ protected:
char *pstr;
public:
CStrOne( char str[ ])
{ pstr=str;
}
void show()
{ cout<<"strings="<<pstr<<endl;
}
};
class CStrTwo:public CStrOne
{
char *newpstr;
public:
CStrTwo( char str1[ ],char str2[ ]):CStrOne(str1)
{ newpstr=str2;
}
void show()
{ cout<<"strings1="<<pstr<<endl;
cout<<"strings2="<<newpstr<<endl;
}
void joint()
{
char temp[100];
strcpy(temp, pstr);
newpstr=strcat(temp,newpstr);
cout<<newpstr<<endl;
}
};
void main()
{
CStrTwo str("My Name is Lian",", 45 years old");
str.show();
str.joint();
}
这段程序把 char temp[100];
strcpy(temp, pstr);
newpstr=strcat(temp,newpstr);
cout<<newpstr<<endl;
改成
newpstr=strcat(pstr,newpstr);
cout<<newpstr<<endl;
为什么结果不一样呢?