I am trying to refresh myself on some C++ programming and I am wondering about the following use of vectors.
If I have the following
#include <iostream>
#include <vector>
//using namespace std;
int main()
{
std::vector<int> thevector;
std::vector<int> other;
thevector.push_back(2);
thevector.push_back(3);
for(int i=0; i< thevector.size();i++)
std::cout<<thevector[i];
std::cout<<std::endl;
other.push_back(100);
other.push_back(200);
other.push_back(300);
thevector = other;
for(int i=0; i< thevector.size();i++)
std::cout<<thevector[i];
return 0;
}
My questions are:
- Is this safe and correct? What if I do this but 1000 times in a loop?
- What happens to the values that were in the original
thevectorwhen this is written withother? Isn't there the possibility of a memory leak?