std::copy_n
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
ヘッダ <algorithm> で定義 | ||
template<class InputIt, class Size, class OutputIt > OutputIt copy_n( InputIt first, Size count, OutputIt result ); | ||
Copies exactly count
values from the range beginning at first
to the range beginning at result
, if count>0
. Does nothing otherwise.
目次 |
[編集]パラメータ
first | - | the beginning of the range of elements to copy from |
count | - | number of the elements to copy |
result | - | 目的の範囲の始まり Original: the beginning of the destination range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
型の要件 | ||
-InputIt は InputIterator の要件を満たさなければなりません。 | ||
-OutputIt は OutputIterator の要件を満たさなければなりません。 |
[編集]値を返します
Iterator in the destination range, pointing past the last element copied if count>0
or first
otherwise.
[編集]複雑性
Exactly count
assignments, if count>0
.
[編集]可能な実装
template<class InputIt, class Size, class OutputIt> OutputIt copy_n(InputIt first, Size count, OutputIt result){if(count >0){*result++=*first;for(Size i =1; i < count;++i){*result++=*++first;}}return result;} |
[編集]例
Run this code
#include <iostream>#include <string>#include <algorithm>#include <iterator> int main(){std::string in ="1234567890";std::string out; std::copy_n(in.begin(), 4, std::back_inserter(out));std::cout<< out <<'\n';}
出力:
1234
[編集]参照
(C++11) | 指定範囲の要素を新しい位置にコピーします (関数テンプレート) |