stdmake_pair
std::make_pair is a function in the C++ standard library that creates a pair object with two values provided as arguments. The function takes two arguments, one for the first value and another for the second value, and returns a pair object containing these values.
Here's an example of how to use std::make_pair:
#include <iostream>
#include <utility>
int main() {
int a = 10;
double b = 3.14;
// Create a pair object using std::make_pair
std::pair<int, double> myPair = std::make_pair(a, b);
// Access the values of the pair object
std::cout << "First value: " << myPair.first << std::endl;
std::cout << "Second value: " << myPair.second << std::endl;
return 0;
}
Output:
First value: 10
Second value: 3.14
In this example, std::make_pair is used to create a pair object with an integer value a and a double value b. The resulting pair object myPair can then be accessed using the first and second member variables
原文地址: https://www.cveoy.top/t/topic/iM5j 著作权归作者所有。请勿转载和采集!