Parameters of make_pair()

  • key: Represents the key for the pair object i.e. first value.
  • value: Represents the value for the pair object i.e. second value.

std::make_pair() in C++

In C++, std::make_pair() is a standard library function that is used to construct a key-value pair from the given arguments. The type of the pair constructed is deduced automatically from the type of arguments. It is defined as a function template inside the <utility> header file.

Similar Reads

Syntax of std:make_pair()

std::make_pair(key, value);...

Parameters of make_pair()

key: Represents the key for the pair object i.e. first value.value: Represents the value for the pair object i.e. second value....

Return Value of make_pair()

The make_pair() function returns an object of std::pair having first and second elements as key and value passed as argument....

Example of make_pair()

C++ // C++ program to illustrate // std::make_pair() function in C++ #include #include using namespace std; int main() { // Pair Declared pair p1; // Pair Initialized using make_pair() p1 = make_pair(1, "GeeksforGeeks"); // using it with auto type deduction auto p2 = make_pair("GeeksforGeeks", 1); // Pair Printed cout << "Pair 1: " << p1.first << ", " << p1.second << endl; cout << "Pair 2: " << p2.first << ", " << p2.second; return 0; }...