How to make a tuple and unpack 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, s2 ; float pi ; char ch;
    
    std::tie(s1, s2, pi, ch) = record;
    
    std::cout << s1 << ' ' << s2 << ' ' << pi << ' ' << ch << std::endl;
}


/*
run:

One Million Digits of PI 3.14159 U

*/

 



answered Dec 30, 2024 by avibootz
edited Dec 30, 2024 by avibootz

Related questions

2 answers 267 views
3 answers 321 views
1 answer 132 views
3 answers 212 views
1 answer 175 views
2 answers 157 views
...