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

phpMailer not working ..........
HI,
I was playing with the phpMailer script and tried to send a smiple mail using their test scri

Sessions work for me and not others?
I'm having a bit of bad luck with sessions. In the past they have worked fine for me, but this time

Function module "DPS_CHECK_TABLE_EXISTS" not found (after OSS 1422843 impl)
Dear All,

I implemented Note OSS 1422843.

When i execute the new report RSPO20

error help - Dynamic Image
I've been working on making my site less cluttered in the directories and more secure lately. In an

How would I convert this into code using an if statement?
ES equals exam score m equals $mean s equals $total. I already coded my mean and total so I'm not g

Using mysql_real_escape_string for displayed content
On my website users can input data into a textarea and it will store it in the mysql database. But,

Solution to the FindControl problem
I have seen may posts about having problems with the FindControl method. Most seem to come about bec

Setting condidtions for an input box
Hi all,

I would like to set a condition in a txt box that says the number a user enters has t

Count number of records in all the tables with a querry URGENT PLEASE...
I downloaded ORACLE 9I DATA DUMP into my comp. There are number of tables. I need to find out the

Help with simple query
Hi,

I'm trying to do a Query with a Union where I want to print the number of rows $tc conta

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