12. c++ STL tuple
1. get getを使用して要素にアクセスします. 2. tie pairまたはtuple. にバンドルされた値をtieの変数に順次代入します. reference https://where-i-go.tistory.com/25?category=817926
#include <iostream>
#include <tuple>
using namespace std;
int main(void)
{
tuple<int,int,int> t1 = make_tuple(1,2,3);
cout << get<0>(t1) << '\n';
cout << get<1>(t1) << '\n';
cout << get<2>(t1) << '\n';
return 0;
}
複数の値を組み合わせることができるtuple. #include <iostream>
#include <tuple>
using namespace std;
int main(void)
{
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';
x=y=z=0;
cout << x << ' ' << y << ' ' << z << '\n';
tie(x,y,z) = t;
cout << x << ' ' << y << ' ' << z << '\n';
x=y=z=0;
tie(x,y,ignore) = t;
cout << x << ' ' << y << ' ' << z << '\n';
return 0;
}
Reference
この問題について(12. c++ STL tuple), 我々は、より多くの情報をここで見つけました https://velog.io/@kth811/12.-c-STL-tupleテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol