vectors basic doubt


I have a code which defines a vector as
1
2
unsigned int nx=37;
vector <unsigned> nNodes (1,nx);


Does this mean that nNodes is a vector of 1 position with value=37 (37) or that nNodes is a vector of 2 positions with values 1 and 37 (1,37)

Thanks,


Ramon

Last edited on
It means that nNodes has one element with the value 37.

One day you will also be able to read the reference pages. ;)
http://www.cplusplus.com/reference/vector/vector/vector/
http://en.cppreference.com/w/cpp/container/vector/vector

EDIT: If you want the vector to contain 2 elements with the values 1 and 37 you can use curly brackets instead.
1
2
unsigned int nx=37;
vector <unsigned> nNodes {1, nx};
Last edited on
Thank you so much @Peter87
Topic archived. No new replies allowed.