C++.阅读程序,写出运行结果,求大神
#include"string.h"classSample{private:char*str;public:Sample(char*s){str=newchar[strl...
#include
"string.h"
class Sample{ private: char *str;
public : Sample(char *s
){str=new char[strlen(s)+1];
strcpy(str,s); 第8页
}
void
disp(){cout<<"str="<<str<<endl;}
运行结果:
char & operator[](int);
};
char &
Sample::operator[](int i)
{return *(str+i);}
void main()
{ char *s="olympics";
Sample obj(s); obj.disp();
int n=strlen(s);
while(n>=0){ obj[n-1]=obj[n-1]-32; n--; }
obj.disp();
} 展开
"string.h"
class Sample{ private: char *str;
public : Sample(char *s
){str=new char[strlen(s)+1];
strcpy(str,s); 第8页
}
void
disp(){cout<<"str="<<str<<endl;}
运行结果:
char & operator[](int);
};
char &
Sample::operator[](int i)
{return *(str+i);}
void main()
{ char *s="olympics";
Sample obj(s); obj.disp();
int n=strlen(s);
while(n>=0){ obj[n-1]=obj[n-1]-32; n--; }
obj.disp();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询