fill
指定された範囲のすべての要素に同じ新しい値を割り当てます。
template<class ForwardIterator, class Type>
void fill(
ForwardIterator _First,
ForwardIterator _Last,
const Type& _Val
);
パラメーター
_First
スキャン対象範囲の最初の要素の位置を示す前方反復子。_Last
スキャン対象範囲の最後の要素の一つ前の位置 1 に対処前方反復子。_Val
範囲 [_First、_Last) 要素に割り当てる値。
解説
先の範囲は有効である必要があります; すべてのポインターが必要 dereferenceable 最後の位置は incrementation によって最初からアクセスできます。複雑度は、範囲のサイズと直線的です。
使用例
// alg_fill.cpp
// compile with: /EHsc
#include <vector>
#include <algorithm>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1;
vector <int>::iterator Iter1;
int i;
for ( i = 0 ; i <= 9 ; i++ )
{
v1.push_back( 5 * i );
}
cout << "Vector v1 = ( " ;
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
cout << *Iter1 << " ";
cout << ")" << endl;
// Fill the last 5 positions with a value of 2
fill( v1.begin( ) + 5, v1.end( ), 2 );
cout << "Modified v1 = ( " ;
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
cout << *Iter1 << " ";
cout << ")" << endl;
}
必要条件
ヘッダー: <algorithm>
名前空間: std