How to empty (clear) a 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);
    
    dq.clear();
    
    printdq(dq);
  
    return 0; 
} 
  
  
  
/*
run:
  
5 2 9 12 7 9 13 89 
  
*/

 



answered Jul 22, 2020 by avibootz

Related questions

1 answer 137 views
1 answer 191 views
191 views asked Dec 9, 2020 by avibootz
1 answer 169 views
1 answer 152 views
1 answer 202 views
2 answers 285 views
...