c++程序填空
1. 在下面程序横线处填上适当内容,使程序执行结果为:"hello, andylin"。#include <iostream>
#include <cstring>
using namespace std;
class mystring
{public:
char * pdata;
mystring(int len)
{pdata=new char[len+1];
}
~mystring()
{delete pdata;}
void show(){cout<<pdata<<endl;}
};
void fun(mystring** array,int len)
{mystring*old=*array;
_______;
memcpy(*array, old, len);
}
void main()
{mystring str(20);
mystring*pstr=&str;
mystring**ppstr=&pstr;
strcpy(str.pdata,"hello,andylin");
fun(ppstr, 20);
_______
}
新手请求帮忙解读一下,三克油啦 #include <iostream>
#include <cstring>
using namespace std;
class mystring
{
public:
char *pdata;
mystring(int len)
{
pdata = new char;
}
~mystring()
{
delete pdata;
}
void show() { cout << pdata << endl; }
};
void fun(mystring **array, int len)
{
mystring *old = *array;
//调用mystring的构造函数,用以后续的复制操作
*array = new mystring(len);
memcpy(*array, old, len);
}
int main(void)
{
mystring str(20);
mystring *pstr = &str;
mystring **ppstr = &pstr;
strcpy(str.pdata, "hello,andylin");
fun(ppstr, 20);
//直接使用str输出,也可以(**ppstr).show()
str.show();
}
页:
[1]