The Wayback Machine - https://web.archive.org/web/20180428033715/http://ja.cppreference.com:80/w/cpp/algorithm/copy_n
名前空間
変種
操作

std::copy_n

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
実行ポリシー (C++17)
非変更シーケンス操作
(C++11)(C++11)(C++11)
(C++17)
変更シーケンス操作
copy_n
(C++11)
(C++11)

未初期化記憶域の操作
分割操作
ソート操作
バイナリサーチ操作
集合操作 (ソート済み範囲に対する)
ヒープ操作
(C++11)
最小/最大演算
(C++11)
(C++17)
順列
数値演算
C のライブラリ
 
ヘッダ <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.
型の要件
-
InputItInputIterator の要件を満たさなければなりません。
-
OutputItOutputIterator の要件を満たさなければなりません。

[編集]値を返します

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;}

[編集]

#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

[編集]参照

指定範囲の要素を新しい位置にコピーします
(関数テンプレート)[edit]
close