【c++程序】关于operator
2015-10-18 16:18
295 查看
/********************************************************/ /**************---About 符号的重载-------**************/ /**************---Author: Tibruce Zhao-----**************/ /**************---Date: 2015/10/18------***************/ /********************************************************/ #include<iostream> using namespace std; class F { int n; int d; public: F(int n=0,int d=1):n(n),d(d){} void print(bool newline=true); void input(); int getn() const {return n;} int getd() const {return d;} friend istream& operator>>(istream& in,F& f);//有元,可以访问私有成员 }; //void operator>>(istream &in,int& n){} istream& operator>>(istream& in,F& f) { char c; in>>f.n>>c>>f.d; return in; } ostream& operator<<(ostream& out,const F& f) { out<<"分子"<<f.getn()<<'/'<<"分母"<<f.getd(); return out; } int main() { F a,b; int n; cin>>a>>b; //cin.operator>>(a); operator>>(cin,a) //cin>>n; //operator>>(int& __n); operator>>(cin,n) cout<<a<<b; //cout.operator<<(a); operator(cout,a); return 0; }
相关文章推荐
- 【C语言】 跳水比赛名次预测问题
- 自由精神世界~分支结构
- 求二叉树中和为特定值的路径
- No.1 定时器接口timer的设计
- 第二章 构造函数语意学 成员们的初始化队伍
- 【转载】:【C++跨平台系列】解决STL的max()与numeric_limits::max()和VC6 min/max 宏冲突问题
- 剑指offer第二十题【包含min函数的栈】c++实现
- C++11中值得关注的几大变化
- [C++] STACK_Principle
- 【黑马训练营】IOS C语言指针
- C语言---数组,字符串数组,冒泡排序
- C语言 实现一个函数,判断一个数是不是素数
- C语言 实现一个函数判断year是不是润年
- C++STL之双端队列容器
- C语言 使用函数实现两个数的交换
- C语言——getc()和putc()
- 【黑马训练营】IOS C语言Foundation框架
- C语言——fopen()和fclose()
- C语言的内存管理
- C语言总结错误