#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

struct
Area { Area():x(0), y(0) {} Area(int a, int b):x(a),y(b){} int x,y; bool operator<(const Area &rhs) { return x<rhs.x; } //排序用到 friend ostream& operator<<(ostream &out, const Area &rhs); //输出用到 }; ostream& operator<<(ostream &out, const Area &rhs) { out << "["<< rhs.x <<"," << rhs.y << "]"; return out; } int _tmain(int argc, _TCHAR* argv[]) { vector<Area> vec; vec.push_back(Area(7,2)); vec.push_back(Area(5,6)); vec.push_back(Area(1,8)); copy(vec.begin(), vec.end(), ostream_iterator<Area>(cout, " ")); cout << endl; sort(vec.begin(), vec.end()); copy(vec.begin(), vec.end(), ostream_iterator<Area>(cout, " ")); cout << endl; }

The copy() function copies the elements between start and end to dest.
ostream_iterator<Area>(cout, " "):定义输出流迭代器

相关文章:

  • 2021-08-11
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2021-12-23
  • 2021-12-29
  • 2022-01-16
  • 2021-12-15
  • 2021-05-20
  • 2022-01-28
  • 2022-12-23
相关资源
相似解决方案