关于vector使用迭代器访问和下标访问
  • 板块学术版
  • 楼主Bodhi
  • 当前回复13
  • 已保存回复13
  • 发布时间2023/5/6 22:30
  • 上次更新2023/10/23 16:28:49
查看原帖
关于vector使用迭代器访问和下标访问
364848
Bodhi楼主2023/5/6 22:30

RT,做P2262的时候使用了vector,但是当我使用迭代器访问的时候就会爆RE,而使用下标访问的时候就没事,请问这是为什么呢?

//迭代器
for (vector<Task>::iterator it = tasks.begin(); it != tasks.end(); ++it)
{
	if (it->type == UPLOAD)
		file.uploadUpdate(it->fl, (it->restSize - userFlux <= 0 ? it->restSize : userFlux));
	it->restSize -= userFlux;
	if (it->restSize <= 0)
	{
		--userTotal;
		if (it->type == UPLOAD)
			file.cancelUpload(it->fl);
		userFlux = (userTotal == 0 ? maxUserFlux : min(maxServerFlux / userTotal, maxUserFlux));
		tasks.erase(it);
	}
}
//下标
for (int j = 0; j < tasks.size(); ++j)
{
	if (tasks[j].type == UPLOAD)
		file.uploadUpdate(tasks[j].fl, (tasks[j].restSize - userFlux <= 0 ? tasks[j].restSize : userFlux));
	tasks[j].restSize -= userFlux;
	if (tasks[j].restSize <= 0)
	{
		--userTotal;
		if (y == UPLOAD)
			file.cancelUpload(tasks[j].fl);
		userFlux = (userTotal == 0 ? maxUserFlux : min(maxServerFlux / userTotal, maxUserFlux));
		tasks.erase(find(tasks[j].user));
	}
}
2023/5/6 22:30
加载中...