gpt4 book ai didi

c++ - vector 迭代器的索引

转载 作者:搜寻专家 更新时间:2023-10-31 01:06:10 24 4
gpt4 key购买 nike

所以我有一个基本的 vector 迭代器,它看起来像:

for (std::vector<string>::iterator i = vec.begin(); i != vec.end(); ++i)
{
// Need the index here
}

我试过使用 &i 但它只返回 true。我需要返回索引。我需要创建自己的整数吗?

最佳答案

如果“ID”是指索引,请使用

i - vec.begin()

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com