STL Queue of C Plus Plus Programming Language

STL Queue of C Plus Plus Programming Language

Instructor-svgAl-Mamun Sarkar
Apr 03 , 2020

STL Queue of C Plus Plus Programming Language. The following code shows how to use queue in C++ programming language.

 

Code:

#include <iostream>
#include <queue>

int main ()
{
  std::queue<int> test_queue;
  int sum (0);

  for (int i=1;i<=10;i++) 
      test_queue.push(i);

  while (!test_queue.empty())
  {
     std::cout << test_queue.front() << std::endl;
     sum += test_queue.front();
     test_queue.pop();
  }

  std::cout << "total: " << sum << '\n';

  return 0;
}

 

Output:

1
2
3
4
5
6
7
8
9
10
total: 55

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram