C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ Vector end()This function returns an iterator referring to the past-last-element in the vector container.
Syntax
Consider a vector v. Syntax would be: iterator it=v.end() Parameter
It does not contain any parameter. Return valueIt returns an iterator following the last element. Example 1
Let's see a simple example.
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> v{10,20,20,40};
vector<int>::iterator it;
for(it=v.begin();it!=v.end();it++)
cout<<*it<<" ";
return 0;
}
Output: 10 20 20 40 In this example, elements of the vector have been iterated using begin() and end() function. Example 2Let's see another simple example.
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string> v{"Welcome","to","javaTpoint"};
vector<string>::iterator it;
for(it=v.begin();it!=v.end();it++)
cout<<*it<<" ";
return 0;
}
Output: Welcome to javaTpoint In this example, strings of vector have been iterated using begin() and end() function.
Next TopicC++ Vector
|