设置std :: vector< int>到一个范围 [英] Set std::vector<int> to a range
本文介绍了设置std :: vector< int>到一个范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将 std :: vector< int>
设置为范围的最佳方法是什么?所有数字介于3到16之间?
您可以使用 std :: iota 如果您有C ++ 11支持或正在使用 STL :
std :: vector< int& v(14)。
std :: iota(v.begin(),v.end(),3);
或自行实现。
如果你可以使用 boost
,那么一个不错的选项是 boost.irange :
std :: vector< int> v;
boost:push_back(v,boost :: irange(3,17));
What's the best way for setting an std::vector<int>
to a range, e.g. all numbers between 3 and 16?
解决方案
You could use std::iota if you have C++11 support or are using the STL:
std::vector<int> v(14);
std::iota(v.begin(), v.end(), 3);
or implement your own if not.
If you can use boost
, then a nice option is boost.irange:
std::vector<int> v;
boost::push_back(v, boost::irange(3, 17));
这篇关于设置std :: vector< int>到一个范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文