C++

tuple

King94 2020. 5. 1. 14:04

#include<tuple>

 

<code>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<queue>
#include<tuple>
#include<vector>
using namespace std;
int main(void){
    tuple<int,int,int> a;
    a=make_tuple(1,2,3);
    cout<<get<0>(a)<<" "<<get<1>(a)<<' '<<get<2>(a)<<endl;
    cout<<"///////////////////////////////////"<<endl;
    cout<<"vector<tuple<int,int,int> > > "<<endl;
    vector<tuple<int,int,int> > s;
    s.push_back(make_tuple(2,3,4));
    for(auto &w : s)
    {
        cout<<get<0>(w)<<" "<<get<1>(w)<<" "<<get<2>(w)<<endl;
    }
    cout<<"use iterator "<<endl;
    vector<tuple<int,int,int> > ::iterator iter;
    for(iter=s.begin();iter!=s.end();iter++)
    {
        cout<<get<0>(*iter)<<" "<<get<1>(*iter)<<" "<<get<2>(*iter)<<endl;
    }
    cout<<"/////////////////////////////////// "<<endl;
    cout<<"queue<tuple<int,int,int> > "<<endl;
    queue<tuple<int,int,int> > q;
    q.push(make_tuple(5,6,7));
    int z,x,c;
    tie(z,x,c)=q.front();
    cout<<z<<" "<<x<<" "<<c<<endl;
    
    return 0;
    
}
cs

<결과 >