Use operator of less than (<) : pair « map multimap « C++ Tutorial






#include <utility>
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char** argv){
  pair<string, int> myPair("hello", 5), myOtherPair;

  myOtherPair.first = "hello";
  myOtherPair.second = 6;

  pair<string, int> myThirdPair(myOtherPair);

  if (myPair < myOtherPair) {
    cout << "myPair is less than myOtherPair\n";
  } else {
    cout << "myPair is greater than or equal to myOtherPair\n";
  }

  return (0);
}








23.17.pair
23.17.1.Assign value directly to first and second
23.17.2.Default constructor for pair
23.17.3.Using copy constructor to create another pair
23.17.4.Use operator of less than (<)
23.17.5.Use operator of equal (=)
23.17.6.Use make_pair() function to create a pair
23.17.7.Create a pair object that will contain the result of a call to insert()
23.17.8.Create a pair object that holds the result of insert()
23.17.9.Using a Pair to store int and string
23.17.10.Vector of pair
23.17.11.Sort a vector of pairs