[C++] iota语句的语法
生活随笔
收集整理的這篇文章主要介紹了
[C++] iota语句的语法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
頭文件為 numeric
#include <numeric> using namespace std;語法和 sort / lower_bound / upper_bound 等差不多,都是前閉后開的原則。
iota(A+x,A+y,z) :表示將 AAA 數(shù)組的 [x,y)[x,y)[x,y) 區(qū)間進行填充,從 zzz 開始,每填一個 z+1z+1z+1。即 A[x,y)?[z~z+y?x)A[x,y)\leftrightarrow [z\sim z+y-x)A[x,y)?[z~z+y?x)。
#include <cstdio> #include <numeric> using namespace std; int a[100]; int main() {iota( a + 5, a + 10 + 1, 2 );for( int i = 0;i <= 20;i ++ )printf( "%d ", a[i] );return 0; } //output:0 0 0 0 0 2 3 4 5 6 7 0 0 0 0 0 0 0 0 0 0換言之,這個等價于一個 for 循環(huán)。
for( int i = x;i < y;i ++, z ++ ) A[i] = z;總結
以上是生活随笔為你收集整理的[C++] iota语句的语法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用SoftICE破解Winzip8.0
- 下一篇: U盘量产工具