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/p/3050156.html