在本教程中,我们将讨论C ++标准模板库中用于理解配对的程序。
Pair是在实用程序头中定义的容器,其中包含两个值。它用于合并两个值并将它们关联,即使它们是不同类型也是如此。
#include <iostream>
#include <utility>
using namespace std;
int main(){
//初始化一对
pair <int, char> PAIR1 ;
PAIR1.first = 100;
PAIR1.second = 'G' ;
cout << PAIR1.first << " " ;
cout << PAIR1.second << endl ;
return 0;
}输出结果
100 G