std::fill_n
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
Defined in header <algorithm> | ||
template<class OutputIt, class Size, class T > void fill_n( OutputIt first, Size count, const T& value ); | (C++11以前) (C++11およびそれ以降) | |
value
場合count
で範囲の先頭で最初first
要素に指定された値count>0
を割り当てます。そうでなければ何もしません.Original:
Assigns the given value
value
to the first count
elements in the range beginning at first
if count>0
. Does nothing otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集]パラメータ
first | - | 変更する要素の範囲の先頭 Original: the beginning of the range of elements to modify The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count | - | 変更する要素の数 Original: number of elements to modify The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
value | - | 値が割り当てられる Original: the value to be assigned The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
型の要件 | ||
-OutputIt は OutputIterator の要求を満足しなければなりません。 |
[編集]値を返します
(なし)(C++11以前)
Original:
(none) (C++11以前)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
count>0
、first
そうでない場合、割り当てられた最後の要素の反復子1。 (C++11およびそれ以降)Original:
Iterator one past the last element assigned if
count>0
, first
otherwise. (C++11およびそれ以降)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集]複雑性
count
ため正確count>0
割り当て、.Original:
Exactly
count
assignments, for count>0
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集]可能な実装
template<class OutputIt, class Size, class T> OutputIt fill_n(OutputIt first, Size count, const T& value){for(Size i =0; i < count; i++){*first++= value;}return first;} |
[編集]例
次のコードは、整数のベクタの最初の半分に-1を代入する
fill_n()
使用しています Original:
The following code uses
fill_n()
to assign -1 to the first half of a vector of integers: The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
このコードを実行します
#include <algorithm>#include <vector>#include <iostream> int main(){std::vector<int> v1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; std::fill_n(v1.begin(), 5, -1); for(vector<int>::iterator it = v1.begin(); it != v1.end();++it){std::cout<<*it <<" ";}std::cout<<"\n";}
出力:
-1 -1 -1 -1 -1 5 6 7 8 9
[編集]参照
要素の範囲を特定の値を割り当てます Original: assigns a range of elements a certain value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) |