프로그래밍/C,C++
[C/C++] STL pair, tuple 사용법
노력의천재
2022. 3. 15. 22:45
C++에 튜플이 있는지 첨 알았다!!! WOW
#include<bits/stdc++.h>
using namespace std;
pair<int, int> p;
tuple<int, int, int> t;
int a, b, c;
int main() {
// 원래 방법
p = make_pair(1, 2);
t = make_tuple(1, 2, 3);
a = p.first;
b = p.second;
cout << a << " " << b << "\n";
a = get<0>(t);
b = get<1>(t);
c = get<2>(t);
cout << a << " " << b << " " << c << "\n";
// tie 함수를 이용하는 방법
p = {1, 2};
t = make_tuple(1, 2, 3);
tie(a, b) = p;
cout << a << " " << b << "\n";
tie(a, b, c) = t;
cout << a << " " << b << " " << c << "\n";
}