首页 > 编程语言 > 详细

c++11:copy_n

时间:2014-10-13 16:10:00      阅读:272      评论:0      收藏:0      [点我收藏+]

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 }

 

c++11:copy_n

原文:http://www.cnblogs.com/457220157-FTD/p/4022117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!