
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Numeric Library - iota
Description
It is used to store increasing sequence and assigns to every element in the range [first,last) successive values of val, as if incremented with ++val after each element is written.
Declaration
Following is the declaration for 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 − It iterators to the initial and final positions in a sequence.
val − It is an initial value for the accumulator.
Return Value
none
Exceptions
It throws if any of the assignments or increments throws.
Data races
The elements in the range [first1,last1) are accessed.
Example
In below example for 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; }
The output should be like this −
numbers are : 10 11 12 13 14
numeric.htm
Advertisements