http://blog.csdn.net/calvin_zcx/article/details/6072286
Http://www.linuxidc.com/Linux/2014-10/107621.htm
Header files: <utility>
Comparison rules for the pair's <, >, <=, >=, = =,! =: Compare second before comparing First,first (you can re-specify your own comparison logic by overloading these operators)
The initialization of pair: pair<string, int> prt; Pair<string, INT>PR2 ("Hello", 5); pair<string, int> PR3 = make_pair<string, int> ("haha", 4); PAIR<STIRNG, INT>PR4 = Make_pair ("lll", 3);
Pair and vector interaction: pair<string, vector<int>> student;
Pair access element: Pair<int, int> a (n);
cout<< "first=" <<a.first<< "------" << "second=" <<a.second;
Pair using typedef technique: typedef pair<string, int> Nameinfo;
Nameinfo info ("Lucy", 4);
Pair and standard input stream: pair<string, string> input;
while (Cin>>input.first>>input.second) {cout<< ' info is ' <<input.first<< ': ' << Input.second<<endl;}
(PS: Tips for using cin directly abc[enter]d---->info is abc:d)
The implicit conversion of pair: Pair can accept implicit type conversion, which can achieve higher flexibility. However, the following problems can occur: for example, there are two definitions:
Pair<int, float> (1, 1.1);
Make_pair (1, 1.1); The Make_pair function converts the second variable to a double type. The problem in programming is the need to draw attention.
Make_pair<int, float> (1,1.1); If you want to specify a float, you can indicate the type like this.
A small example of a vector applying a pair:
STL's Pair Learning