C/C++编程技巧

C++:vector元素排序

2020-04-18  本文已影响0人  AI秘籍

vector内元素按升序存储:

#include <opencv2/opencv.hpp>
#include <iostream>
 
#pragma comment(lib,"opencv_world341.lib")
 
using namespace cv;
using namespace std;
int main()
{
    vector<Point2f> pts_v{ Point2f(100,200),Point2f(300,150),Point2f(200,400) };
    sort(pts_v.begin(), pts_v.end(), 
            [](Point2f pts1, Point2f pts2) {return pts1.x < pts2.x; });
    cout << pts_v << endl;
 
    return 0;
}
 
 
//
vector<Rect> temp;
std::sort(temp.begin(), temp.end(), 
          [](Rect& rect1, Rect& rect2) { return rect1.x < rect2.x; }
         );
image.png

参考:

  1. https://blog.csdn.net/sss_369/article/details/88983580
上一篇 下一篇

猜你喜欢

热点阅读