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
Post a Comment