如何使用C ++ / STL执行以下操作?我想std::vector
用一系列值[最小,最大)填充。
# Python
>>> x = range(0, 10)
>>> x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
我想我可以使用std::generate_n
并提供函子来生成序列,但是我想知道是否有使用STL进行此操作的更简洁方法?
在C ++ 11中,有std::iota
:
#include <vector>
#include <numeric> //std::iota
std::vector<int> x(10);
std::iota(std::begin(x), std::end(x), 0); //0 is the starting number
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句