?? 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 + -