7.20


pair에서는


#include<pair>

#include<queue>


queue<pair<int,int>> a;

a.push(make_pair(1,2))를 하면 1과2를 넣을 수 있고,


a.front().first 로 1에 접근

a.front().second 로 2에 접근 가능하다.



tuple은 pair와 다르게 first와 second로 접근하지 못한다.

tuple을 사용할 때 접근법은


#include<tuple>

#include<queue>


일단, queue(큐)와 tuple을 이용하니 두 헤더를 넣어준 후


queue<tuple<int, int, int>> q;


q.push(make_tuple(a, b, c)); 이라고 하면  queue에 a,b,c라는 int가 들어가는데,


이때 각각 접근하려면


a get<0>(q.front());

b get<1>(q.front());

c get<2>(q.front());


으로 접근 가능하다.

반응형

+ Recent posts