c++ tuple push_back
#include <iostream>
#include <tuple>
#include <vector>
int main() {
std::vector<std::tuple<int, double>> vec;
// Creating a tuple
std::tuple<int, double> myTuple = std::make_tuple(10, 3.14);
// Pushing the tuple into the vector
vec.push_back(myTuple);
return 0;
}
Include Libraries: Import necessary libraries (
iostream
,tuple
,vector
) for input/output, tuples, and vectors.Main Function: Define the main function where the program execution begins.
Vector Declaration: Create a vector named
vec
that stores tuples holding an integer and a double (std::tuple<int, double>
).Tuple Creation: Create a tuple named
myTuple
initialized with values10
(integer) and3.14
(double) usingstd::make_tuple
.Pushing into Vector: Use
vec.push_back(myTuple)
to add themyTuple
tuple into thevec
vector. This appendsmyTuple
to the end of the vector.