日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

c语言iota怎么用,C++ std::iota用法及代码示例

發布時間:2023/12/3 c/c++ 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言iota怎么用,C++ std::iota用法及代码示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

存儲順序遞增

分配val的[first,last]個連續值范圍內的每個元素,就像在寫入每個元素之后以++ val遞增。

模板:

void iota (ForwardIterator first, ForwardIterator last, T val);

參數:

first, last

Forward iterators to the initial and final positions of the sequence

to be written. The range used is [first, last), which contains all the

elements between first and last, including the element pointed by

first but not the element pointed by last.

val

Initial value for the accumulator.

返回類型:

None

// CPP program to illustrate

// std::iota

#include // std::cout

#include // std::iota

// Driver code

int main()

{

int numbers[10];

// Initailising 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 << '\n';

return 0;

}

輸出:

Elements are:100 101 102 103 104 105 106 107 108 109

應用:

它可用于生成連續的數字序列。

// CPP program to generate

// a sequence of numbers using std::iota

#include // std::cout

#include // std::iota

// Driver code

int main()

{

int numbers[11];

// Initailising 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 << '\n';

return 0;

}

輸出:

Elements are:10 11 12 13 14 15 16 17 18 19 20

總結

以上是生活随笔為你收集整理的c语言iota怎么用,C++ std::iota用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。