zoukankan      html  css  js  c++  java
  • 重载<<.>>(friend必须吗?)

    #include <iostream>
    using namespace std;

    class position{
    public:
        position(
    int m,int n);
        friend ostream 
    & operator <<(ostream & out,const  position & s);
        friend istream 
    & operator >>(istream & in,position & s);
        
    int x;
        
    int y;
    }
    ;
    void main()
    {
        position m(
    3,4);
        cout
    <<m<<endl;

     cout
    <<"输入x,y\n";
        cin
    >>m;
        cout
    <<m<<endl;
    }

    position ::position(
    int m,int n) :x(m),y(n){}
    ostream 
    & operator<< (ostream & out,const position & s)
    {
        
    out<<"(" << s.x<<",";
        
    out<<s.y << ")\n";
        
    return out;
    }

    istream 
    & operator>> (istream & in,position & s)
    {
        
    in>>s.x;
        
    in>>s.y;
        
    return in;
    }


  • 相关阅读:
    数据结构算法练习(一)
    crontab详解
    git遇到问题
    docker容器管理
    docker及服务器遇到的坑
    shell study
    低级终端IO
    高级IO
    信号处理
    UNIX日期与时间
  • 原文地址:https://www.cnblogs.com/cutepig/p/940524.html
Copyright © 2011-2022 走看看