Which practice of iteration through containers is preferred


Posted on 16th Feb 2014 07:03 pm by admin

In the "real world" what kind of loop do most people use to iterate through a container like a vector.

A loop like this...
Code: for (int i = 0; i < v.size(); ++i) { // do whatever}Or like this...
Code: for (vector::iterator i = v.begin(); i != v.end(); ++i) { // do whatever}In addition to this question, I'm also wondering what's preferred in terms of output of a container. Iterating through its elements (like shown above) or using the copy algorithm with a stream iterator like this.

Code: ostream_iterator os(cout);copy(v.begin(), v.end(), os);Just some general coding practice questions for those in the industry. Any information is appreciated. Thanks.

No comments posted yet

Your Answer:

Login to answer
83 Like 47 Dislike
Previous forums Next forums
Other forums

post to self
Trying to get my form to submit to itself. However I am also trying to use an image for my submit bu

Help with captcha script needed
Hello,

I am working on a script where reCAPTCHA or a similar form of CAPTCHA will be used, f

button help
i originally had this but realised it is much easier to have a button.

Code: <?php

SMTP server...
I recently found a tutorial online on SMTP authentification for sending emails from webpages, here i

How to generate a random array of integers subject to a certain constraint
I am writing a program that asks the user to enter an integer N and then generates a random array of

Google Wave
So... has anyone used it yet? Is it any good?

http://wave.google.com/help/wave/about.html#vid

Linkage between two scripts
Okay say I have this for a link in a script:

Code: <li><a href="#&q

Please help with SMTP Authenticated PHP Email Form
Hello, I'm creating a PHP email form, and for this particular server, I have to use SMTP Authenticat

question about stripslashes and real_escape_string
im cleaning up an old app that I wrote fixing some of the vulernabilities from attacks.

I hav

JQuery, Masterpage, and Control issue
Hey everyone, I am using JQuery in several sites so I thought it would be best to place the library

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash