Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,988 questions

51,933 answers

573 users

How to use tuple in C++

4 Answers

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

int main() {
    std::tuple<char, int, float> tpl{'z', 165774, 2.891};

    std::cout << get<0>(tpl) << ' ' << get<1>(tpl) << ' ' <<  get<2>(tpl);
}

 
 
 
/*
run:
 
z 165774 2.891
 
*/

 



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

int main() {
    std::tuple<char, int, float> tpl{'z', 165774, 2.891};
    
    get<0>(tpl) = 'x';

    std::cout << get<0>(tpl) << ' ' << get<1>(tpl) << ' ' <<  get<2>(tpl);
}

 
 
 
/*
run:
 
x 165774 2.891
 
*/

 



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

int main() {
    std::tuple<char, int, float> tpl{'z', 165774, 2.891};
    
    auto& [ch, num, pi] = tpl;
 
    std::cout << ch << ' ' << num << ' ' << pi;
}

 
 
 
/*
run:
 
z 165774 2.891
 
*/

 



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

int main() {
    auto tpl = std::make_tuple(93535, "c++", 3.14);
    
    std::cout << std::get<int>(tpl)
              << ' ' << std::get<const char *>(tpl)
              << ' ' << std::get<double>(tpl);
}

 
 
 
/*
run:
 
93535 c++ 3.14
 
*/

 



answered Dec 9, 2023 by avibootz

Related questions

2 answers 119 views
1 answer 211 views
2 answers 243 views
1 answer 128 views
128 views asked Feb 8, 2020 by avibootz
...