解答下指针和数组的问题
#include<iostream.h>
#include<math.h>
#include<string.h>
class CString
{
private:
char*p_str;
public:
CString(char*p_s)
{
p_str=new char [strlen(p_s)+1];
strcpy(p_str,p_s);
}
void print(){cout<<p_str<<endl;}//若将p_str改为*p_str,输出会是abcdef;这是为啥呢?
~CString(){delete[]p_str;}
};
void main()
{
char p[20];
CString *p_strPtr=NULL;
cout<<"Enter a string:";
cin>>p;
CString s1("a string");
p_strPtr=&s1;
p_strPtr->print();//*p_str啥时候指向字符串"a string"
delete p_strPtr;//加上这一行会出现调试错误界面,这是为啥呢?
}