将值从struct类型推送到队列

时间:2016-11-09 01:42:13

标签: c++ struct queue

我正在尝试检查推送到队列容器(仍然对容器感到困惑)是否成功。但是我无法打印队列的前端和后端元素。非常感谢帮助。错误是什么时候我尝试尝试在队列ready_q前面做cout。

#include<iostream>
#include<fstream>
#include<queue>

using namespace std;

const int process_cnt=22;


struct process{

  int at;
  float bt;
  float rt;};

 process init_q[process_cnt];

 void read_file(ifstream& inData,process init_q[]);

 int main(){

      ifstream inData;

      read_file(inData,init_q);

      queue<process> ready_q;
  for (int i=0;i<process_cnt;i++){
      ready_q.push(init_q[i]);
      cout << "The first element is " << ready_q.front()
  << " and the last element is " << ready_q.back() << endl;  /*check if push to ready_q was successful*/

      }



  cout<<"Test";

  return 0;
  }

 void read_file(ifstream& inData,process init_q[]){


 inData.open("input.txt");

 while(inData){
      for(int i=0;i<process_cnt;i++){
      inData >>init_q[i].at >> init_q[i].bt;
      cout <<init_q[i].at<<" "<<init_q[i].bt<<endl;/*check if read was successful*/
  }
  cout<<"Read Successful in read_file"<<endl;
  }
 inData.close();

  }

0 个答案:

没有答案