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 7696001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:40:43+00:00 2026-05-31T21:40:43+00:00

This may seem like an odd question but I was talking to a friend

  • 0

This may seem like an odd question but I was talking to a friend today who was ranting about today’s C++ programmers and how they just don’t do things quite right. He said his main pet peeve was the abuse of iterating, in code like this:

for(int i = 0; i<((int) someVector.size()); ++i){
    //Something here
}

instead of the more traditional

vector::iterator i;
for(i = someVector.begin(); i!=someVector.end(); ++i){
    //Something here
}

While I understand both methods, is there any particular reason why the second is superior to the first? Is it performance? Or some other factor?

  • 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-05-31T21:40:44+00:00Added an answer on May 31, 2026 at 9:40 pm

    Neither one of those is good style.

    The first has a useless and dangerous cast.

    The second allows the iteration variable to leak outside the loop’s scope, and doesn’t use an equality test, and uses a post-increment on an iterator, which makes a useless copy.

    Better is:

    using std::begin, std::end;
    for( auto it = begin(container), end_it = end(container); it != end_it; ++it )
    

    This works with any STL container, arrays, and any container you provide with begin and end helper functions.

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

Sidebar

Related Questions

This may seem like an odd question, but I need to find a closed-source
This may seem like an odd question, but I have my own reasons for
This may seem like an odd question, but I'm looking for a comment generator
This may at first seem like an odd question, but when a cin request
This may seem like an odd question, but does anyone know the origin of
This may seem like a daft question, but i was wondering about how to
This may seem like a simple question but i am getting an error when
This may seem like a stupid question, but what message do i send to
This may seem like a silly question but I can't figure it out. let's
This may seem like a realy basic question but... How do you use double

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.