std::set_intersection 求交的时候,如果传入的是vector 必须要同序
https://www.programiz.com/cpp-programming/online-compiler/
#include <iostream> using namespace std; int main() {cout << "Hello, world!" << endl;std::vector<int> exclude_express_province_code_list {31,21};std::vector<int> user_city_ids{31,21};std::set_intersection(exclude_express_province_code_list.begin(),exclude_express_province_code_list.end(), user_city_ids.begin(),user_city_ids.end(), std::back_inserter(exclude_ids));cout << exclude_ids.size();return 0; }
输出2
// Online C++ compiler to run C++ program online #include <iostream> #include <vector> #include <algorithm> #include <set> #include <functional> // std::plusint main() {// Write C++ code here// std::cout << "Try programiz.pro";std::vector<int> exclude_express_province_code_list {22,31};std::vector<int> user_city_ids{31,22};std::vector<int> exclude_ids;std::set_intersection(exclude_express_province_code_list.begin(),exclude_express_province_code_list.end(), user_city_ids.begin(),user_city_ids.end(), std::back_inserter(exclude_ids));std::cout << exclude_ids.size() << std::endl;return 0; }
输出1