填空题
有如下的程序:
#include <iostream>
#include <cstring>
using namespace std;
class rev{
char*s;
public:
rev(const char*s){
this->s=new char[strlen(s)+1];
strcpy(this->s,s);
}
rev(rev &r){
s=new char[strlen(r.s)+1];
for(int i=0;i<strlen(r.s);i++)s[i]=r.s[strlen(r.s)-1-i];
s[strlen(r.s)]=0;
}
~rev() {delete s;}
friend ostream& operator<<(ostream&,const rev &);
};
ostream& operator<<(ostream &os,const rev &c){
for(int i=strlen (c.s)-1;i>=0;i--) os<<c.s[i];
return os;
}
int main() {
char *p="Hello,world!";
rev hay("Hay!");
cout<<rev(p)<<endl;
cout<<rev(hay);
return0;
}
执行上面的程序将输出
1。