Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7730391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:12:48+00:00 2026-06-01T06:12:48+00:00

Possible Duplicate: C++ STL: Which method of iteration over a STL container is better?

  • 0

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

Assuming an std::vector<int> named numbers, which of the following is faster?

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

or..

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

Which one is faster? Is there any significant difference?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:12:50+00:00Added an answer on June 1, 2026 at 6:12 am

    Those two aren’t even comparable. The former loops through each element, while the latter loops through while checking if the current index is valid (with at()). Take out the check and ask again:

    for (/* Not an int! Unsigned type: */ std::size_t i = 0; i < numbers.size(); i++)
        cout << numbers[i];
    

    Now they do the same thing. And now the question is a duplicate (#1 #2). To summarize: it doesn’t matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Which sorting algorithm is used by STL’s list::sort()? Which sorting algorithm can
Possible Duplicate: In STL maps, is it better to use map::insert than []? I
Possible Duplicate: C++: Easiest way to initialize an STL vector with hardcoded elements I'm
Possible Duplicate: Is it ok to cast a STL container with Base type to
Possible Duplicate: Good STL-like library for C Are there any open source C libraries
Possible Duplicate: Why is the C++ STL is so heavily based on templates? (and
Possible Duplicate: Sort list using stl sort function The C++ standard library gives strict
Possible Duplicates: C++, removing #include<vector> or #include<string> in class header Forward declare an STL
Possible Duplicate: C++ STL set update is tedious: I can't change an element in
Possible Duplicate: C++ STL set update is tedious: I can't change an element in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.