// StructQuenceTestDemo.cpp : 定义控制台应用程序的入口点。
//目的:测试结构体类型的队列,查看是否如何初始化其内存空间
#include "stdafx.h"
#include <string>
#include <iostream>
#include <queue>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
struct STUDENT
{
string name;
int age;
};
STUDENT a[3];
a[0].name="qin";
a[0].age=1;
a[1].name="de";
a[1].age=2;
a[2].name="qiang";
a[2].age=3;
queue <STUDENT> studentInfro;
for (int i=0;i<3;i++)
{
studentInfro.push(a[i]);
}
cout<<"队列的长度是"<<studentInfro.size()<<endl;
int num=studentInfro.size();
for (int i=0;i<num;i++)
{
STUDENT b;
b=studentInfro.front();
studentInfro.pop();
cout<<b.name<<endl;
cout<<b.age<<endl;
cout<<endl;
}
/*STUDENT b;
b=studentInfro.front();
studentInfro.pop();
cout<<b.name<<endl;
cout<<b.age<<endl;
cout<<endl;*/
return 0;
}
关于结构体队列的使用前是否需要初始化的问题
最新推荐文章于 2020-05-13 15:22:12 发布