解答编程题
发布时间: 2024-06-28 10:44:39
Ⅰ c++语言编程题两题,希望高手帮解答一下,谢谢!
第一题:
#include<iostream>
#include<cstring>
usingnamespacestd;
classString
{
friendostream&operator<<(ostream&output,String&a);
friendintmain();
private:
intsize;
char*str;
public:
String(char*a);
};
String::String(char*a)
{
str=a;
size=strlen(a);
}
ostream&operator<<(ostream&output,String&a)
{
inti;
intn=a.size;
for(i=0;i<n;i++){
output<<a.str[i];
}
returnoutput;
}
intmain()
{
char*a="Helloworld!";
cout<<a<<endl;
Strings=String(a);
cout<<s;
cin.get();
return0;
}