What is the tuple class in C++


This code uses the vector container I have used before with another example, please check or search in my blog.

We can store two value items using a "tuple". The tuple class is simple, you declare a list of the types of items in the tuple object in the declaration between the angle brackets. So the tuple<string, int> declaration says that the object will hold a string and an integer.

The make_tuple function is provided by the C++ Standard Library and will create a tuple object containing 2 values.

The push_back function will put the item into the vector container.

You can hold a lot of things in the tuple function
Ex: tuple<string, int, string>;
Ex: tuple<char, string, int, string>;

Finally, the "auto" keyword means that that compiler should create a variable with the type of the data that is assigned to it.

What is the tuple class in C++

No comments:

Post a Comment