iota() in C++The iota() function is included in the numeric header file of C++. Every element inside a given range of values is given a new value using the iota() function. After an assignment to an element, the value of the element is increased by 1 by default. In this article, we will discuss about the iota() function with its syntax, parameters, and examples. Syntax:It has the following syntax: Syntax parameters:The following parameters are passed to the iota() method: First: A forward iterator is used to the initial position of the series to be written. Last: The forward iterator is used to write the final point of the sequence. Value:It represents the initial value of the accumulator. Note: Forward iterators are those that can access a range's sequence of elements in the direction that runs from its start to its finish.Return valueNo return value is present. ExampleLet's take an example to understand this function in C++. We can place the elements from index 0 to index 14 in our array because it is size = 15, which is 15. Iota() includes the element pointed by first but excludes the element pointed by last for the range. The accumulator currently has a value of 19, which will increase by 1 after each time a value is assigned to an element until its range is reached. The iota() function's output is: 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Example: 1Output: 12 Elements are: 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Working mechanism:
Example: 2Output: Elements are : 200 201 202 203 204 205 206 207 208 209 210 211 Next TopicTellg() Function in C++ |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India