Is the old vector get cleared? If yes, how and when?

Posted by user180866 on Stack Overflow See other posts from Stack Overflow or by user180866
Published on 2010-04-15T03:17:08Z Indexed on 2010/04/15 3:23 UTC
Read the original article Hit count: 222

Filed under:
|
|

I have the following code:

void foo()
{
    vector<double> v(100,1);       // line 1
    // some code
    v = vector<double>(200,2);     // line 2
    // some code
}

what happened to the vector of size 100 after the second line? Is it gets cleared by itself? If the answer is yes, how and when it is cleared?

By the way, is there any other "easy and clean" ways to change the vector as in line 2? I don't want things like

v.resize(200);
for (int i=0; i<200; i++) v[i] = 2;

© Stack Overflow or respective owner

Related posts about c++

Related posts about vector