How to use structure binding with tuple in C++

2 Answers

0 votes
#include <iostream>
#include <tuple>

int main() {
    std::tuple<char, int, float> tpl{'a', 907, 3.14};

    auto& [ch, num, pi] = tpl;

    std::cout << ch << ' ' << num << ' ' << pi;
}

 
 
 
/*
run:
 
a 907 3.14
 
*/

 



answered Dec 9, 2023 by avibootz
0 votes
#include <iostream>
#include <tuple>

int main() {
    auto&& [ch, num, pi] = std::make_tuple('a', 907, 3.14);

    std::cout << ch << ' ' << num << ' ' << pi;
}

 
 
 
/*
run:
 
a 907 3.14
 
*/

 



answered Dec 9, 2023 by avibootz

Related questions

1 answer 119 views
1 answer 112 views
1 answer 99 views
2 answers 159 views
1 answer 117 views
...