===================== Declaration ==========================
This article is original, reproduced please specify the source and author, and maintain the integrity of the article (including this statement).
This article links:
==================================================
As for why the use of such wonderful things ... For the glory of the tribe.
----------------------------------------------------------------------------------------
Using STL's set in a struct is a bit more complicated than using vectors, and it feels as if the set is stored in a tree, so write "<".
On the sample code.
#include < Iostream> #include <set>using namespace std;struct AA {int a1;int a2;bool operator < (const aa& ODR) const{ Return a1<odr.a1;}}; struct nn{std::set<aa> stset;}; int main (int argc, char* argv[]) {NN stn1;for (int i=6;i>0;i--) {AA sta;sta.a1=i;sta.a2=10*i;stn1.stset.insert (StA);} Std::set<aa>::iterator It=stn1.stset.begin (); Std::set<aa>::iterator itEnd=stN1.stSet.end (); for (; it!= itend;it++) {printf ("vector:a1=%d,a2=%d\n", IT->A1,IT->A2);} printf ("sizeof (NN) =%d\n", sizeof (NN));p rintf ("sizeof (StN) =%d\n", sizeof (stN1));///////////////////////////////// NN stn2;stn2.stset=stn1.stset;stn1.stset.clear (); It=stn2.stset.begin (); itend= StN2.stSet.end (); for (; it!=itend;it++) {printf ("vector:a1=%d,a2=%d\n", IT->A1,IT->A2);} printf ("sizeof (NN) =%d\n", sizeof (NN));p rintf ("sizeof (StN) =%d\n", sizeof (STN2)); return 0;}
===================== Split line and say goodbye to you =======================
Problem solving-using STL in structs