泛型算法之copy,back_inserter

Xredman posted @ Jun 14, 2009 09:57:12 AM in 以前博文 , 2705 阅读

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;

const int N = 10;

int main()
{
        vector<int> v1, v2;
        vector<int>::iterator p;
        v1.clear(); v2.clear();

        for(int i = 1; i <= 10; i++)
                v1.push_back(i);

        copy(v1.begin(), v1.end(), back_inserter(v2));
        //copy算法把一对iterator当做二个参数,用其标记要拷贝的元素范围,
        //第三个实参是一个iterator,标记要拷贝元素将被放置的起始位置
        //back_inserter被称作iterator适配器;使元素被插入到作为实参的vector的尾部。

        p = v2.begin();

        while(p != v2.end())
                cout<<*p++<<endl;
        return 0;
}

 

 






  • 无匹配
  • 无匹配
roblox gratis sin de 说:
Aug 01, 2023 02:56:04 AM

Roblox es un importante proveedor de servicios de juegos en línea que ha tenido un gran éxito en los últimos años. Puede usar Roblox Studio para crear sus propios juegos o jugar juegos creados por otros jugadores. roblox gratis sin descargar La aplicación Roblox está disponible para su descarga gratuita en Android, iOS, Windows y más plataformas. Pero si no quieres descargar la aplicación, hay otra forma de acceder a ella. Roblox está en línea gratis sin tener que descargar la aplicación.

Arunachal Pradesh 7 说:
Aug 26, 2023 12:25:39 AM

Arunachal Pradesh 7th Question Paper 2024 All the Online PDF format Question Papers Provided by Board of Secondary Education Arunachal Pradesh,Arunachal Pradesh Model Question Paper 2024 are Arunachal Pradesh 7th Model Paper 2024 Prepared as per the updated Board of Education in the Arunachal Pradesh State Syllabus to help Students in their exam Preparations, which Aims to build both the Practical knowledge as well as analytical Skills for Arunachal Pradesh Every Student,Arunachal Pradesh Question Paper 2024 are Prepared as per the updated Arunachal Pradesh Syllabus & Exam Pattern to help Students in their Exam Preparations.Arunachal Pradesh Previous Question Paper 2024 will help a lot to the Students.

pavzi.com 说:
Jan 19, 2024 03:57:04 AM

Pavzi.com is a startup by passionate webmasters and bloggers who have a passion for providing engaging content that is accurate, interesting, and worthy to read. pavzi.com We are more like a web community where you can find different information, resources, and topics on day-to-day incidents or news. We provide you with the finest web content on every topic possible with the help of the editorial and content team.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter