gpt4 book ai didi

c++ - 为什么迭代器使用前缀增量形式?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:22:07 25 4
gpt4 key购买 nike

<分区>

Johannes Schaub 声称 here

always use the prefix increment form for iterators whose definitions you don't know. That will ensure your code runs as generic as possible.

for(std::vector<T>::iterator it = v.begin(); it != v.end(); ++it) {
/* std::cout << *it; ... */
}

为什么这不首先迭代它,然后开始循环(在 v.begin() + 1)?

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