0
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
using namespace std;

int main()
{
    struct process
    {
        int burst;
        int ar;
    };
    int x = 4;
    int arival[x];
    int burst[x];
    ifstream arrival, burrst;
    arrival.open("arrival.txt");
    burrst.open("burrst.txt");
    for (int i = 0; i<x; i++)
    {
        arrival >> arival[i];
        burrst >> burst[i];

    }
    arrival.close();
    burrst.close();


    vector<process> a[x];

    for (int i = 0; i<x; i++)
    {
        a[i].push_back({ burst[i], arival[i] });

    }
    cout << "Process\t" << "Arrival Time\t" << "Burst Time\n";
    for (int i = 0; i<x; i++)
    {
        char k = 'A';
        cout << k << "\t" << a[i].back().burst << "\t" << a[i].back().ar << endl;
    }
    queue<process> wait, ready; /* Declare a queue */
    wait.push(a[1]);
    return 0;
}

The compiler is not allowing me to push vector value into queue When I try to insert a[1] in wait queue like this:

wait.push(a[1]);

I get the following error

invalid arguments

Please have a look and help me to remove the error.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402

1 Answers1

1

I think what you are looking for is just a vector of process, not an array of vector of process

Instead of:

vector<process> a[x];

Use:

vector<process> a;

and then, in the for loop, use:

// a[i].push_back({ burst[i], arival[i] });
//  ^^^ drop this.

a.push_back({ burst[i], arival[i] });
R Sahu
  • 204,454
  • 14
  • 159
  • 270