📄 9_7.cpp
字号:
#include<iostream.h>
#include<iomanip.h>
ostream& pxy(ostream& out);
class point //point 类的定义
{
public: //外部接口
point(int a=0, int b=0);//构造函数
friend ostream& operator <<(ostream& out,const point& p);//声明友元函数
private: //私有数据
int x;
int y;
};
//成员函数的实现
point::point(int a,int b)
{
x=a;
y=b;
}
ostream& operator <<(ostream& out,const point& p)//重载<<运算符
{
out<<"x="<<pxy<<p.x<<"y="<<pxy<<p.y<<endl;//使用操纵符pxy设置格式
return(out);
}
ostream& pxy(ostream& out)//自定义操纵符
{
out.flags(ios::left);
out<<setw(3);
return(out);
}
//主程序
int main()
{
point A(1,2),B(3,4);
cout<<A<<B;
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -