Vector problem

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Vector problem

Post by Casval on Mon Apr 14, 2008 11:14 pm
([msg=151]see Vector problem[/msg])

I'm trying to output the values stored in a vector to a text file or just to show the values in the command line.
So far I can't get it done, any suggestions?
Casval
New User
New User
 
Posts: 24
Joined: Mon Apr 14, 2008 7:05 am
Blog: View Blog (0)


Re: Vector problem

Post by TheMindRapist on Tue Apr 15, 2008 10:33 am
([msg=190]see Re: Vector problem[/msg])

Tell us what language you are using and show us the code...
We can't fix the problem with no information...
Image
User avatar
TheMindRapist
Contributor
Contributor
 
Posts: 585
Joined: Mon Apr 14, 2008 4:57 pm
Blog: View Blog (0)


Re: Vector problem

Post by BhaaL on Tue Apr 15, 2008 11:30 am
([msg=193]see Re: Vector problem[/msg])

Sounds pretty much like C++, at least other languages tend to use the terms "List" or "Set" for such collections.

Try this:
Code: Select all
for (std::vector<myType>::iterator it = myVector.begin(); it != myVector.end(); it++) {
   //do stuff to (*it)
   //(*it) is one element from myVector of type myType
}


Other languages are similar, they probably even support foreach constructs (pseudo-code):
Code: Select all
foreach (myType element in myVector) {
   //do stuff to element
}
BhaaL
Poster
Poster
 
Posts: 270
Joined: Sun Apr 13, 2008 11:16 am
Blog: View Blog (0)


Re: Vector problem

Post by Casval on Tue Apr 15, 2008 2:25 pm
([msg=242]see Re: Vector problem[/msg])

It's C++, I forgot to put that in there; my bad.
I can't think up the code off the top of my head, I neglected to save it before I went to bed last night.

Thanks BhaaL, I'll give that a whirl.
Casval
New User
New User
 
Posts: 24
Joined: Mon Apr 14, 2008 7:05 am
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron