在队列中插入向量元素
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");
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 << "Processt" << "Arrival Timet" << "Burst Timen";
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;
}
当我尝试在这样的等待队列中插入a[1]
时,编译器不允许我将矢量值推到队列中:
wait.push(a[1]);
我得到以下错误
无效的参数
请查看并帮助我删除错误。
我认为您正在寻找的只是process
的vector
,而不是process
的vector
数组
而不是:
vector<process> a[x];
使用:
vector<process> a;
然后,在for循环中,使用:
// a[i].push_back({ burst[i], arival[i] });
// ^^^ drop this.
a.push_back({ burst[i], arival[i] });
相关文章:
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 在 C++ 中输出枚举类类型的向量元素
- 用向量的向量元素初始化向量的空向量
- 为什么不允许使用可变长度数组作为向量元素?
- 在函数中传递向量元素
- 使用 Rcpp 加速替换迭代算法中的列表和向量元素是否合法?
- 返回向量元素的 l 值的正确方法是什么?
- 当向量增长时,指向向量元素的C++指针是否无效
- 如何在C++中从一个向量元素减去std::unorderede_map向量元素并更新它
- C++:向量元素赋值导致访问冲突
- 将向量元素与字符串元素进行比较,而不初始化向量
- 从2D矢量中找出最小尺寸的向量元素的更好方法
- 当我尝试将一个向量元素的值分配给另一个向量元素时,为什么我的应用程序会崩溃
- 使用递归C++向量元素的总和
- 如何查找为数组中的最低值编制索引的向量元素
- 限制指针访问STL ::向量元素
- 访问索引指向向量元素时的seg故障 - 做错了什么
- 如何使用指针访问向量元素的各个元素
- 向量元素数据损坏了Find()操作
- 将字符值分配给向量元素.C