최대 1 분 소요

개요

  • n개의 요소를 복사


예제

  • 코드
    #include <algorithm>
    #include <iostream>
    #include <vector>

    using namespace std;

    int main() {
    	vector<int> v1({1, 2, 3, 4, 5});
    	for (const auto &iter : v1) {
    		cout << iter << endl;
    	}

    	cout << "------" << endl;

    	vector<int> v2;

    	copy_n(v1.begin() + 1, 3, back_inserter(v2));

    	for (const auto &iter : v2) {
    		cout << iter << endl;
    	}

    	return 0;
    }
  • 실행 결과
    1
    2
    3
    4
    5
    ------
    2
    3
    4