How to remove the last element from deque in C++

1 Answer

0 votes
#include <iostream> 
#include <deque> 

void printdq(std::deque <int> dq) { 
    for (auto it = dq.begin(); it != dq.end(); ++it) 
        std::cout << *it << " "; 
    std::cout << '\n'; 
} 

int main() 
{ 
    std::deque<int> dq = { 5, 2, 9, 12, 7, 9, 13, 89 }; 
    
    printdq(dq);
    
    std::deque<int>::iterator it = dq.end(); 
    dq.erase(it); 
    
    printdq(dq);
  
    return 0; 
} 
  
  
  
/*
run:
  
5 2 9 12 7 9 13 89 
5 2 9 12 7 9 13 
  
*/

 



answered Jul 22, 2020 by avibootz

Related questions

2 answers 214 views
1 answer 191 views
191 views asked Jul 29, 2020 by avibootz
1 answer 171 views
1 answer 150 views
2 answers 265 views
1 answer 205 views
1 answer 219 views
...