存储递增序列 将val的[first,last]连续值分配给范围内的每个元素,就像在写入每个元素后用++val递增一样。
null
模板:
void iota (ForwardIterator first, ForwardIterator last, T val);Parameters :first, lastForward iterators to the initial and final positions of the sequenceto be written. The range used is [first, last), which contains all theelements between first and last, including the element pointed byfirst but not the element pointed by last.valInitial value for the accumulator. Return Type :None
C++
// C++ program to illustrate // std :: iota #include <iostream> // std::cout #include <numeric> // std::iota // Driver code int main() { int numbers[10]; // Initialising starting value as 100 int st = 100; std::iota(numbers, numbers + 10, st); std::cout << "Elements are :" ; for ( auto i : numbers) std::cout << ' ' << i; std::cout << '' ; return 0; } |
输出:
Elements are : 100 101 102 103 104 105 106 107 108 109
申请: 它可以用来生成一系列连续的数字。
C++
// C++ program to generate // a sequence of numbers using std :: iota #include <iostream> // std::cout #include <numeric> // std::iota // Driver code int main() { int numbers[11]; // Initialising starting value as 10 int st = 10; std::iota(numbers, numbers + 11, st); std::cout << "Elements are :" ; for ( auto i : numbers) std::cout << ' ' << i; std::cout << '' ; return 0; } |
输出:
Elements are : 10 11 12 13 14 15 16 17 18 19 20
本文由 萨钦·比什特 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END