how to delete the context of 2D matrix

Hello everyone,
I have two functions. One, Function 1, produces tuple contains one double and one 1D vector. In the second, Function 2, I run the Function 1 for different kk, so each time I obtained different 1D vector which corresponds to (get<1>(obtained). TI had to build 2D matrix of these 1D vectors by adding them vertically. So, I tried to do that by push_back. The problem, in main function below since I have to do this job for 10 iterations, ecah time start matrix grows up until 5. However, I need to empty the container start before each iteration. Where and how can do that ? Basically, start should not been cumulated. it must be deleted and new vectors must be pushed back.

Thank you so much in advance.

tuple<double, vector<int>>Function 1 (...)
{
return make_tuple(weight, price);
}

double Function 2 (vector<vector< int>> &start)
{
for (int kk = 0; kk < 5; kk++)
{
tuple <double, vector<int>> obtained;
obtained= Function 1 (...)

average= average+ get<0>(obtained);


start.push_back(get<1>(obtained));

}

return average;
}

int main ()
{
double =sum;
vector<vector< int>> &start
for (int iter=0;iter<10;iter++)
double Function 2 (start)

}

Use std::vector::clear() to erase all elements from a vector:

https://en.cppreference.com/w/cpp/container/vector/clear
Thank you so much @MikeyBoy. I am quite learner, it helped thank you so much
@learner999. After 97 posts and you still don't use code tags for the code!


[code]
// formatted code goes here
[/code]

You're welcome. Glad I could help!
Topic archived. No new replies allowed.