declaring iterator in cpp
C++
// C++ program to demonstrate iterators
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// Declaring a vector
vector<int> v = { 1, 2, 3 };
// Declaring an iterator
vector<int>::iterator i;
int j;
cout << "Without iterators = ";
// Accessing the elements without using iterators
for (j = 0; j < 3; ++j)
{
cout << v[j] << " ";
}
cout << "\nWith iterators = ";
// Accessing the elements using iterators
for (i = v.begin(); i != v.end(); ++i)
{
cout << *i << " ";
}
// Adding one more element to vector
v.push_back(4);
cout << "\nWithout iterators = ";
// Accessing the elements without using iterators
for (j = 0; j < 4; ++j)
{
cout << v[j] << " ";
}
cout << "\nWith iterators = ";
// Accessing the elements using iterators
for (i = v.begin(); i != v.end(); ++i)
{
cout << *i << " ";
}
return 0;
}
vector<int>::iterator ptr;
Also in C++:
- Title
- Read multiple files(.txt) c++
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- eratosthenis sieve in c++
- Category
- C++
- Title
- how to swap string characters in c++
- Category
- C++
- Title
- preorder traversal
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- phph date
- Category
- C++
- Title
- console colors in C++
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- nearest integer rounding in c++
- Category
- C++
- Title
- c++ create object
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- c++ string^ to char*
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- c++ excel blank cells
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- c++ iterate through constant list
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- first fit algorithm
- Category
- C++
- Title
- variant hold type
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- ue4 modular character
- Category
- C++
- Title
- primitive and non primitive data types in c++
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- compare values within within a vector c++
- Category
- C++
- Title
- body parser
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- nth_element c++
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- how to compare two strings lexicographically in c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- std::iomanip c++
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- compile c++ program
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- how can make string value in cpp
- Category
- C++
- Title
- passing array to function in c++
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- screen record ios simulator
- Category
- C++
- Title
- insertion c++
- Category
- C++
- Title
- unordered_map c++
- Category
- C++
- Title
- sfml base program
- Category
- C++
- Title
- c++ sort
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- uepic games github
- Category
- C++
- Title
- floor() in c++
- Category
- C++
- Title
- matrix multiplication c++ eigen
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- inverser les éléments d'un tableau manuellement en c++
- Category
- C++
- Title
- c++ uint32_t
- Category
- C++
- Title
- c++ triple
- Category
- C++
- Title
- function declerations in C++
- Category
- C++
- Title
- how to compile opencv c++ in ubuntu
- Category
- C++
- Title
- system("pause") note working c++
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- how to convert qt string to string
- Category
- C++
- Title
- add a timer c++
- Category
- C++
- Title
- map.erase in c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- how to sort vector in c++
- Category
- C++
- Title
- char vector to string c++
- Category
- C++
- Title
- dfs in c++
- Category
- C++
- Title
- maximum possible number atmost k swaps
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- how to check sqrt of number is integer c++
- Category
- C++
- Title
- delete files c++
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- spicoli
- Category
- C++
- Title
- centos7 mlock2
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- c++ modulo make it give only positive numbers
- Category
- C++
- Title
- remove value from vector c++
- Category
- C++
- Title
- int to float c++
- Category
- C++
- Title
- c++ get ascii value of char
- Category
- C++
- Title
- c++ initialize a vector
- Category
- C++
- Title
- insert elements in array in c++11
- Category
- C++
- Title
- what does map.count() return in c++
- Category
- C++
- Title
- find height of a tree
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++