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 277 views
3 answers 330 views
1 answer 139 views
1 answer 206 views
3 answers 222 views
1 answer 183 views
...