目录

iota

描述 (Description)

它用于存储递增序列并分配给val的连续值[first,last]范围内的每个元素,就像在写入每个元素后用++ val递增一样。

声明 (Declaration)

以下是std :: iota的声明。

C++98

	
template <class ForwardIterator, class T>
  void iota (ForwardIterator first, ForwardIterator last, T val);

C++11

template <class ForwardIterator, class T>
  void iota (ForwardIterator first, ForwardIterator last, T val);
  • first, last - 它迭代到序列中的初始和最终位置。

  • val - 它是累加器的初始值。

返回值 (Return Value)

没有

异常 (Exceptions)

如果任何分配或增量抛出则抛出。

数据竞争 (Data races)

访问[first1,last1]范围内的元素。

例子 (Example)

在下面的示例中为std :: iota。

#include <iostream>
#include <numeric>
int main () {
   int numbers[5];
   std::iota (numbers,numbers+10,10);
   std::cout << "numbers are :";
   for (int& i:numbers) std::cout << ' ' << i;
   std::cout << '\n';
   return 0;
}

输出应该是这样的 -

numbers are : 10 11 12 13 14
↑回到顶部↑
WIKI教程 @2018