c++ - How to fill a vector with a range? -


how fill vector numbers 1 10 in c++? have not working.

vector<int>test(10); test={ 1, 10 };

many options. example,

vector<int> test{1,2,3,4,5,6,7,8,9,10}; 

or

std::vector<int> test; test.reserve(10); // prevent reallocations (int = 1; < 11; ++i)   test.push_back(i); 

or

std::vector<int> test(10); std::iota(test.begin(), test.end(), 1); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -