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

FTP issues
Hi all,


I am currently facing some serious problems with a script and really need some ad

Print 'a' to 'z' via for loop
A very simple problem..
How Can I print a to z NOT a to y ?
It is a part of a code where
<

What is SAP Avatar ?
Hi All,

This G.Satish , my boss asked me to explore on SAP Avatar. I searced in internet

Login logout link help
Hi all,

Im new to php and Im having trouble creating a login/logout link for my page that dis

pagination numbering pattern
Hello,

I have following code which works great for pagination. but i have small issue now.

Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t

adding 0 to numbers
Hey guys i need to create a 00001 number in a loop. Is there a better way of forcing a 5 digit numbe

what business processes?
Hi,

A general question. What business processes (like OTC - Order to Cach, P2P, R2R etc)

How would I protect......
I have a from, actually, a good amount of forms. How can I make it so you can't type the characters:

Parse XML
Good day,

I use oempro software and try to parse XMLReturn but it's not working for me, simpl

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