gpt4 book ai didi

c++ - 使用迭代或简单的循环计数器哪个更快?

转载 作者:行者123 更新时间:2023-11-28 03:38:50 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
C++ STL: Which method of iteration over a STL container is better?
Efficiency of vector index access vs iterator access

假设 std::vector<int>名为 numbers , 以下哪个更快?

for (vector<int>::iterator i = numbers.begin(); i != numbers.end(); i++)
cout << *i;

或者..

for (int i = 0; i < numbers.size(); i++)
cout << numbers.at(i);

哪个更快?有什么显着差异吗?

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