#include <iostream>
using namespace std;
#include <cstring>
struct stringy
{
char * str ;
int ct ;
};
void show(const char * , int n =1);
void show(const stringy & , int n=1) ;
void set(stringy & , char *) ;
int main()
{
stringy beany ;
char testing[] = "Reality isn't what it used to be." ;
set(beany ,testing) ;
show(beany) ;
show(beany,2) ;
testing[0] = 'D' ;
testing[1] = 'u' ;
show(testing) ;
show(testing ,3) ;
show("Done!") ;
delete [] beany.str ; //用new创建的char*千万别忘了这个delete
return 0;
}
void set(stringy & stry , char *p)
{
int n = strlen(p);
stry.str = new char [n+1] ;
strcpy(stry.str ,p) ;
stry.ct = n ;
//delete [] stry.ct ;
}
void show(const char * p , int n )
{
if(n==0)
{
return ;
}
else
{
cout<<"testing show:"<<endl;
for(int i=0 ;i<n ;i++)
{
cout<<p<<endl ;
}
}
}
void show(const stringy & stry , int n)
{
if(n==0)
{
return ;
}
else
{
cout<<"Stringy show:"<<endl;
for(int i=0 ;i<n ;i++)
{
cout<<stry.str<<" "<<stry.ct<<endl ;
}
}
}