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

 



answered Jul 30, 2020 by avibootz

Related questions

1 answer 157 views
1 answer 187 views
1 answer 160 views
1 answer 223 views
1 answer 155 views
2 answers 271 views
2 answers 221 views
...