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...
Did you know?Explore Trending and Topic pages for more stories 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

code help - pagination
Hi all, I have this code, basically a user logs into my site and they get this page.

The pro

Display error above the login forum help!
Hi guys. just so you know im not asking for someone to do this for me I just need to be pointed in t

Captcha problem users just refresh and it will let them auto submit again
Users will just re submit and not have to enter the new captcha.. ? Lol but if i refresh the page, t

Web Host List
Here is a list of web hosts that offer PHP and MySQL. It is no where near a full list, but it is mos

Timer control causing error
I recently decided to add a timer control to an existing page that uses AJAX on my site. As soon as

Sending UDP Raw socket
I truly need help on this. I am trying to write a test program that simulate a network environment

matching numbers inside ( )
I know I can match numbers by just [0-9]+, so I thought matching numbers inside ( ) would be somethi

please help me... my password gets encrypted but not able to get in database
hai guys,
please help me... in the following function my password gets encrypted but no

BAPI BBP_INB_DELIVERY_CREATE - material number missing in delivery
Hi Experts,

I was able to successfully create an Inbound delivery with reference to a PO

phpmailer class & pop.gmail.com?
Code: <?php
$mail->IsSMTP();
$mail->Host = "pop.gmail.com";

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