We can create a tuple using the std::make_tuple function:
#include <iostream> #include <tuple> #include <string> int main() /*from w w w.j a v a 2s . c o m*/ { auto mytuple = std::make_tuple<int, double, std::string>(123, 3.14, "Hello World."); std::cout << "The first tuple element is: " << std::get<0>(mytuple) << '\n'; std::cout << "The second tuple element is: " << std::get<1>(mytuple)<< '\n'; std::cout << "The third tuple element is: " << std::get<2>(mytuple) << '\n'; }
Instead of typing a lengthy tuple type, which is std::tuple<int, double, std::string>, we used the auto specifier to deduce the type name for us.