cuốn sách gpt4 ai đã làm

c++ - 递增解引用迭代器

In lại Tác giả: Walker 123 更新时间:2023-11-28 06:00:38 hai mươi bốn 4
mua khóa gpt4 Nike

我正在做 C++ 入门练习 (3.25),我正在尝试增加一个取消引用的迭代器。这是我的想法:

vector  arcNotas(10,0); //hold amount of grades by 10-20-30....90-100
int notas = 0;
auto it = arcNotas.begin();
while (cin >> notas && notas!= 1000) {
it += notas / 10; //move the iterator to the right position
*it++; //increment the quantity of elements in that position
it = arcNotas.begin(); //reset to the initial position
}

但是当我编译它时,编译器说(在第一个“注释”输入之后)“vectơ 迭代器不可递增”。我取消引用 专门用来做这件事……我只是不明白哪里出了问题。我进行了搜索,但我发现的只是递增 thay vì *Nó 的问题。

câu trả lời hay nhất

“迭代器不可递增”消息是一个运行时 错误。是您的实现对迭代器进行了边界检查,并且检测到:

it += notas / 10;

或以下 it++ 导致 超出 arcNotas.end().

您应该修复您的代码以在执行此添加之前检查长度,并修复递增迭代器而不是首先取消引用的问题。

关于c++ - 递增解引用迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33344161/

hai mươi bốn 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress