标题:重载
只看楼主
想你的天空
Rank: 2
等 级:新手上路
威 望:5
帖 子:610
专家分:0
注 册:2004-12-30
 问题点数:0 回复次数:0 
重载
//AB类,重载<<,  >>提供输入,并把输入内容放到文件里面,并输出到屏幕上(main里面可以写除函数外的代码)
#include"iostream.h"
#include"fstream.h"
#include"stdio.h"
class AB
  {  public:
       AB(){}
     friend ifstream& operator >>(ifstream& in,AB& a);
     friend ofstream& operator <<(ofstream& in,AB& a);
     private:
      char ch[100];
  };
main()
{    ifstream in;
    ofstream out;
     AB a(in);
    out.open("abc.txt");
    if(!out.fail())
   {  cout<<"error!"<<endl;
       exit(1);
    }
    in>>a;
    out<<a<<endl;
    out.close();
}
ifstream& operator >>(ifstream& in,AB& a)
{    in>>a.ch;
  return in;
}
ofstream& operator <<(ofstream& out,AB& a)
{    out<<a.ch;
    return out;
}
搜索更多相关主题的帖子: 重载 
2005-03-08 20:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-13011-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.075179 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved