vector::begin() फ़ंक्शन एक द्विदिश इटरेटर है जिसका उपयोग कंटेनर के पहले एलिमेंट की ओर इंगित करने वाले इटरेटर को लौटाने के लिए किया जाता है।
vector::end() फ़ंक्शन एक द्विदिश इटरेटर है जिसका उपयोग कंटेनर के अंतिम एलिमेंट की ओर इंगित करने वाले इटरेटर को लौटाने के लिए किया जाता है।
एल्गोरिथम
Begin Initialize the vector v. Declare the vector v1 and iterator it to the vector. Insert the elements of the vector. Print the elements. End.
उदाहरण कोड
#include<iostream> #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = { 50,60,70,80,90}, v1; //v(मानों के साथ), v1 को वेक्टर के रूप में घोषित करना। vector<int>::iterator it; //एक इटरेटर घोषित करना it = v.insert(v.begin(), 40); //begin() फ़ंक्शन का उपयोग करके शुरुआत में निर्दिष्ट स्थिति के साथ v वेक्टर में एक मान डालना। it = v.insert(v.begin(), 1, 30); //begin() फ़ंक्शन का उपयोग करके शुरुआत में निर्दिष्ट स्थिति के साथ v वेक्टर में उसके आकार के साथ एक मान डालना। cout << "The vector1 elements are: "; for ( it = v.begin(); it != v.end(); ++it) cout << *it << " "<<endl; // v वेक्टर के मान प्रिंट करना v1.insert(v1.begin(),v.begin(),v.end()); //begin() और end() फ़ंक्शन का उपयोग करके शुरुआत से अंत तक सभी मान डालना, v वेक्टर के v1 वेक्टर में शुरुआत में begin() फ़ंक्शन का उपयोग करके इंगित करना। cout << "The vector2 elements are: "; for (it = v1.begin(); it != v1.end(); ++it) cout << *it << " "<<endl; // v1 वेक्टर के मान प्रिंट करना return 0; }
आउटपुट
The vector1 elements are: 30 40 50 60 70 80 90 The vector2 elements are: 30 40 50 60 70 80 90