c++ - inserting vector element in queue -
#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"); (int = 0; i<x; i++) { arrival >> arival[i]; burrst >> burst[i]; } arrival.close(); burrst.close(); vector<process> a[x]; (int = 0; i<x; i++) { a[i].push_back({ burst[i], arival[i] }); } cout << "process\t" << "arrival time\t" << "burst time\n"; (int = 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 queue */ wait.push(a[1]); return 0; } the compiler not allowing me push vector value queue when try insert a[1] in wait queue this:
wait.push(a[1]); i following error
invalid arguments
please have , me remove error.
i think looking vector of process, not array of vector of process
instead of:
vector<process> a[x]; use:
vector<process> a; and then, in loop, use:
// a[i].push_back({ burst[i], arival[i] }); // ^^^ drop this. a.push_back({ burst[i], arival[i] });
Comments
Post a Comment