整數類_重載輸入輸出符

描述
定義整數類,重載 >> <<運算符

在這裏插入圖片描述

#include<iostream>
using namespace std;
class Z               //定義類Z
{ public:
    int a;
    Z(){}
    Z(int s){a=s;}
    friend istream&operator >>(istream&input,Z&p){
      input>>p.a;}
    friend ostream&operator <<(ostream&output,Z&p){
        output<<p.a;}
};
int main()
{Z j;
cin>>j;
cout<<j;}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章