C++ mem_fun

 1 #include <stdio.h>
 2 #include <string>
 3 #include <iostream>
 4 #include <fstream>
 5 #include <iterator>
 6 #include <vector>
 7 #include <algorithm>
 8 #include <map>
 9 using namespace std;
10 
11 
12 class Student
13 {
14 private:
15     int sno;
16 public:
17     Student(int i)
18     {
19         sno=i;
20     }
21     int getSno()
22     {
23         return sno;
24     }
25     void printSno()
26     {
27         cout<<sno<<endl;
28     }
29     
30 };
31 vector<Student*> student_p;;
32 void insertStudent(int& sno)
33 {
34     Student*sp=new Student(sno);
35     student_p.push_back(sp);
36 }
37 
38 int  main()
39 {
40     
41     ifstream is("1");
42 
43     istream_iterator<int> ii(is);
44     istream_iterator<int> eos;
45 
46     vector<int> v(ii,eos);
47 
48     for_each(v.begin(),v.end(),insertStudent);
49     for_each(student_p.begin(),student_p.end(),mem_fun(&Student::printSno));
50 
51     return 0;
52 }

 

转载于:https://www.cnblogs.com/mengqingzhong/archive/2013/04/28/3050156.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值