How to initialize a vector in C++ [duplicate]

I want to initialize a vector like we do in case of an array.

Example

int vv[2] = {12, 43};

But when I do it like this,

vector<int> v(2) = {34, 23};

OR

vector<int> v(2);
v = {0, 9};

it gives an error:

expected primary-expression before ‘{’ token

AND

error: expected ‘,’ or ‘;’ before ‘=’ token

respectively.

2 Answers
2

Leave a Comment