Labs ICT
Pro Login

Queue

1 min read | C++ Tutorial

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

C++ Queue

std::queue follows the FIFO (First In, First Out) principle. Elements are added at the back with push() and removed from the front with pop(). Access the front element with front() and the back with back(). Queues model real-world lines and are used in BFS and task scheduling.

#include <iostream>
#include <queue>

int main() {
    std::queue<std::string> q;
    q.push("first");
    q.push("second");
    q.push("third");
    std::cout << "Front: " << q.front() << "\n";
    q.pop();
    std::cout << "Front after pop: " << q.front();
    return 0;
}