33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <cstring>
using namespace std;
class A{
char name[32];
int areacode;
int prefix;
int num;
public:
A(char *s,int i,int j,int k)
{
strcpy(name,s);
areacode = i;
prefix = j;
num = k;
}
friend ostream &operator<<(ostream &stream,A o);
};
ostream &operator<<(ostream &stream,A o)
{
stream<<o.name<<" ";
stream.fill('0');
stream.width(3);
stream<<"("<<o.areacode<<") ";
stream.width(8);
stream<<o.prefix<<"-";
stream.width(4);
stream<<o.num<<endl;
return stream;
}
int main()
{
A ob1("AAA",111,22222,333);
A ob2("BBB",444,55555,666);
A ob3("CCC",777,88888,999);
cout<<ob1<<ob2<<ob3;
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
class A;
ostream &operator<<(ostream &stream,A o);
class A
{
char name[32];
int areacode;
int prefix;
int num;
public:
A(char *s,int i,int j,int k)
{
strcpy(name,s);
areacode = i;
prefix = j;
num = k;
}
friend ostream &operator<<(ostream &stream,A o);
};
ostream &operator<<(ostream &stream,A o)
{
stream<<o.name<<" ";
stream.fill('0');
stream.width(3);
stream<<"("<<o.areacode<<") ";
stream.width(8);
stream<<o.prefix<<"-";
stream.width(4);
stream<<o.num<<endl;
return stream;
}
int main()
{
A ob1("AAA",111,22222,333);
A ob2("BBB",444,55555,666);
A ob3("CCC",777,88888,999);
cout<<ob1<<ob2<<ob3;
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
class A{
char name[32];
int areacode;
int prefix;
int num;
public:
A(char *s,int i,int j,int k)
{
strcpy(name,s);
areacode = i;
prefix = j;
num = k;
}
friend ostream &operator<<(ostream &stream,A o)
{
stream<<o.name<<" ";
stream.fill('0');
stream.width(3);
stream<<"("<<o.areacode<<") ";
stream.width(8);
stream<<o.prefix<<"-";
stream.width(4);
stream<<o.num<<endl;
return stream;
}
};
int main()
{
A ob1("AAA",111,22222,333);
A ob2("BBB",444,55555,666);
A ob3("CCC",777,88888,999);
cout<<ob1<<ob2<<ob3;
return 0;
}