1. 程式人生 > >過載提取和插入運算子

過載提取和插入運算子

struct A
{
    int a;
    int b;
};
istream& operator>>(istream&in,A&k)
{
    return in>>k.a>>k.b;
}
ostream& operator<<(ostream&os,A&k)
{
    return os<<k.a<<" "<<k.b;
}
int main()
{
   A k;
   cin>>k;
   cout<<k<<endl;
   return 0;
}

輸入輸出流類引數和返回必須用引用