一、概述
案例:c++测试queue的用法
二、代码
#include <iostream> #include <queue> #include <string> using namespace std; class Person{ public: Person(string name,int age){ this->m_name = name; this->m_age = age; } string m_name; string m_age; }; void test(){ queue<Person> q; Person p1("tony",30); Person p2("luoluoyang",3); Person p3("kiki",18); //入队列 q.push(p1); q.push(p2); q.push(p3); cout <<"size:"<<q.size()<<endl; //遍历队列集合 while(!q.empty()){ Person pFront = q.front(); Person pBack = q.back(); cout << "begin element name:"<<pFront.m_name<< " age:"<< pFront.m_age<<endl; cout << "end element name: "<<pBack.m_name<< " age: "<<pBack.m_age<<endl; //出队列 q.pop(); } cout <<"size: "<<q.size()<<endl; } /** * * 队列queue测试。先进先出集合 * */ int main(int argc, char const *argv[]) { test(); return 0; }