How to make a tuple and unpack a part of the tuple values into variables with C++

1 Answer

0 votes
#include <iostream>

int main() {
    auto record = std::make_tuple("One Million", "Digits of PI", 3.14159, 'U');
    
    std::string s1 ; float pi ; char ch;
    
    std::tie(s1, std::ignore, pi, ch) = record; // std::ignore helps drop the place name
    
    std::cout << s1 << ' ' << pi << ' ' << ch << std::endl;
}


/*
run:

One Million 3.14159 U

*/

 



answered Dec 30, 2024 by avibootz

Related questions

2 answers 266 views
3 answers 320 views
1 answer 132 views
1 answer 197 views
3 answers 212 views
1 answer 174 views
...