[C++] pair 클래스

Yewon Choi·2020년 6월 22일
0

C++

목록 보기
5/9

pair 클래스란?

  • 두 객체를 하나의 객체로 취급할 수 있게 묶어주는 클래스.
  • 데이터 쌍

사용법

  • pair<type1, type2> p
  • p.first
  • p.second
  • make_pair(변수1, 변수2)
  • operator 사용가능
  • sort() 사용가능

pair 예제 구현코드

#include <iostream>
#include <utility>

using namespace std;

int main(void){
	pair<int, string> p1 = make_pair(1, "one");
	pair<int, string> p2 = make_pair(2, "two");
	pair<int, string> p3 = make_pair(1, "asdfasdf");
	pair<int, string> p4 = make_pair(999, "one");
	
	cout << p1.first << endl;
	cout << p1.second << endl;
}
profile
https://github.com/devAon 찰나의 개발흔적을 남기는 개발블로그 입니다 🐥 https://aonee.tistory.com 에서 Velog로 블로그 이전 작업중입니다 ! 🎶

0개의 댓글