Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,402 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,110 people online right now. Registration is fast and FREE... Join Now!




No loop for outputing elements of a vector

 
Reply to this topicStart new topic

No loop for outputing elements of a vector

jayhuang
29 Oct, 2006 - 05:38 PM
Post #1

New D.I.C Head
*

Joined: 11 Oct, 2006
Posts: 31


My Contributions
I was thinking how to use iterators to output elements of a vector.

It is obviously easy with loops, but without loops, sounds hard for me to output the elements.

Did I miss any good stuff in iterators?
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: No Loop For Outputing Elements Of A Vector
29 Oct, 2006 - 05:57 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
I'm not sure I understand the question...are you asking for a way in which to display (output) all the elements in a vector without using a loop?
User is offlineProfile CardPM
+Quote Post

jayhuang
RE: No Loop For Outputing Elements Of A Vector
29 Oct, 2006 - 09:35 PM
Post #3

New D.I.C Head
*

Joined: 11 Oct, 2006
Posts: 31


My Contributions
QUOTE(Amadeus @ 29 Oct, 2006 - 06:57 PM) *

I'm not sure I understand the question...are you asking for a way in which to display (output) all the elements in a vector without using a loop?


yes, the only way I know to display the elements would be to use loop. Even when declare iterators, I will use loop to scan iterator from begin() to !end(). I have no idea how to do it without loop.
User is offlineProfile CardPM
+Quote Post

Xing
RE: No Loop For Outputing Elements Of A Vector
29 Oct, 2006 - 10:01 PM
Post #4

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Any good reason for not wanting to use loops ?
User is offlineProfile CardPM
+Quote Post

Antiokus
RE: No Loop For Outputing Elements Of A Vector
30 Oct, 2006 - 08:42 AM
Post #5

D.I.C Head
**

Joined: 6 Sep, 2006
Posts: 127



Thanked: 1 times
My Contributions
print every element manually? why dont you want to use a loop?
User is offlineProfile CardPM
+Quote Post

jayhuang
RE: No Loop For Outputing Elements Of A Vector
30 Oct, 2006 - 09:23 PM
Post #6

New D.I.C Head
*

Joined: 11 Oct, 2006
Posts: 31


My Contributions
because I like to seek unusual ways of doing things. Loops are easy and common. I am pretty sure there is a way to do it with only iterators. My friend once showed off that technique to me and I couldn't recall that now.
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: No Loop For Outputing Elements Of A Vector
31 Oct, 2006 - 12:47 AM
Post #7

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
Lol

you make your own jeopardy......


their are step,..funtions..use them wisely
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: No Loop For Outputing Elements Of A Vector
31 Oct, 2006 - 02:11 AM
Post #8

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(jayhuang @ 30 Oct, 2006 - 10:23 PM) *

because I like to seek unusual ways of doing things. Loops are easy and common. I am pretty sure there is a way to do it with only iterators. My friend once showed off that technique to me and I couldn't recall that now.

Hi

Actually they are not really that unusual.

You have input and output iterators. Both are pointers and the STL implements increment and decrement operators

For input, you can try:
CODE
while ( first != last ) // add extra condition if you want to
  ++first;


For output:
CODE
while ( first != last )
  ++first;


hope this helps you.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:12AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month