运算符重载练习(二)

Code:
  1. #include <iostream>   
  2. #include <sstream>   
  3. using namespace std;   
  4. class two   
  5. {   
  6. public:   
  7. bool operator==(const char& right)   
  8. {   
  9.  return (ch == right);   
  10. }   
  11. friend ostream& operator<<(ostream& os,const two& right)   
  12. {   
  13.       return os << right.ch;    
  14. }   
  15. friend istream& operator>>(istream& is,two& right)   
  16. {   
  17.  return is >> right.ch;   
  18. }   
  19. private:   
  20.   char ch;   
  21. };   
  22. int main()   
  23. {   
  24.     two t;   
  25.     bool flag = true;   
  26.     stringstream stream("hello world");   
  27.     while (stream >> t)   
  28.     {   
  29.      cout << t;   
  30.      if ((t == 'o') && (flag == true))   
  31.      {   
  32.       cout << " ";   
  33.       flag = false;   
  34.      }   
  35.     }   
  36.     return 0;   
  37. }   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值