c++11:copy_n

copy_n:

Copies exactly count values from the range beginning at first to the range beginning at result, if count>0.

从源处拷贝n个数到目标处

  1 #include <iostream>
  2 #include <vecotr>
  3 #include <list>
  4 #include <algorithm>
  5 
  6 using namespace std;
  7 
  8 int main()
  9 {
 10     int str[] = { 1, 2, 3, 4, 5};
 11     int dst[5] {};
 12 
 13     copy_n(str, 5, dst);
 14     for (auto &v : str)
 15         cout << v << " ";
 16     cout << endl;
 17 
 18     vector<int> v_s { 1, 2, 3 ,4, 5};
 19     vector<int> v_d;
 20     list<int> l_d;
 21 
 22     copy_n(v_s.begin(), 5, v_d.begin());
 23     for (auto &v : v_d)
 24         cout << v << endl;
 25 
 26     copy_n(v_s.begin(), 5, l_d.begin());
 27     for (auto &v : l_d)
 28         cout << v << endl;
 29 }
原文地址:https://www.cnblogs.com/457220157-FTD/p/4022117.html