#include <iostream>
#include <tuple>
int main() {
auto t = make_tuple(1, 2, 3);
int x = get<0>(t);
int y = get<1>(t);
int z = get<2>(t);
cout << x << ' ' << y << ' ' << z << '\n'; //1 2 3
x = y = z = 0;
cout << x << ' ' << y << ' ' << z << '\n'; //0 0 0
std::tie(x, y, z) = t;
cout << x << ' ' << y << ' ' << z << '\n'; //1 2 3
x = y = z = 0;
std::tie(x, y, ignore) = t; //세번째 자리는 무시 키워드 : ignore
cout << x << ' ' << y << ' ' << z << '\n'; //1 2 0
return 0;
}
pair, tuple으로 묶인 녀석들을 던저서 여러 변수에 한번에 받아 올 수 있습니다.
'C_C++' 카테고리의 다른 글
up casting , down casting (0) | 2023.02.03 |
---|---|
google coding style (0) | 2022.12.17 |
namespace 에 대해 (0) | 2022.12.05 |
stringstream (0) | 2022.12.04 |
클래스 상속 (0) | 2022.11.27 |