Assigning values to an existing vector

If a vector v has already been defined. And only later on you want to reassign values to that vector, would you be able to assign values to it as such or is there a better/correct way to do this?


1
2
3
4
5
6
7
8
//in some above code you have defined the vector 
std::vector<int> v;
 

// later on you want to assign values to it given it is empty would you do it this way: ?

std::vector<int> v{x,x,x,x}


Many thanks
1
2
3
4
5
6
7
std::vector<int> vec { 0, 1, 2, 3, 4 } ;

vec = { 15, 16, 17, 18, 19, 20, 21, 22, 23 } ;

vec.assign( 100, 34 ) ; // 100 items, each item has a value of 34

// etc. 

Topic archived. No new replies allowed.