쌍은 두 개의 데이터 개체로 구성된 간단한 컨테이너입니다.
‘first’ = The first element is referenced as ‘first’ ‘second’ = the second element and the order is fixed (first, second).
쌍을 할당, 비교 및 복사할 수 있습니다. 유형이 다를 수 있는 두 값을 결합하는 데 사용됩니다.
구문은 :pair변수명(datavalue1, datavalue2).
알고리즘
Begin Write pair<data type1,data type 2>variable name(datavalue1,datavalue2) Print the pairs End
예시 코드
#include<iostream>
using namespace std;
int main() {
pair <char,int> value('a',7);
pair <string,double> fruit ("grapes",2.30);
pair <string,double> food ("pulao",200);
cout<<"The value of "<<value.first<<" is "<<value.second <<endl;
cout<<"The price of "<<fruit.first<<" is Rs. "<<fruit.second <<endl;
cout<<"The price of "<<food.first<<" is Rs. "<<food.second <<endl;
return 0;
} 출력
The value of a is 7 The price of grapes is Rs. 2.3 The price of pulao is Rs. 200