Anonymous
4
Q:

advance in c++

// C++ program to illustrate 
// using std::advance 
#include <bits/stdc++.h> 
  
// Driver code 
int main() 
{ 
    // Vector container 
    std::vector<int> vec; 
  
    // Initialising vector 
    for (int i = 0; i < 10; i++) 
        vec.push_back(i * 10); 
  
    // Printing the vector elements 
    for (int i = 0; i < 10; i++) { 
        std::cout << vec[i] << " "; 
    } 
  
    std::cout << std::endl; 
  
    // Declaring the vector iterator 
    std::vector<int>::iterator it = vec.begin(); 
  
    // Printing alternate elements 
    while (it < vec.end()) { 
        std::cout << *it << " "; 
        std::advance(it, 2); 
    } 
} 
0

New to Communities?

Join the community