# Data Structures (COMP 15), Tufts University, Day 22: April 16, 2014, 10:30-11:45am

loop you’ve got a begin you’ve got a conditional when you end and then you’ve got an increment in there here’s what you’re actually doing you’re actually printing out in this case these are just just that’s just an extra character and then you are saying give me what word is pointing to word is an iterator that points to some place in the in the vector and it says dereference that and print it out okay and then I’m going to print this other character let me show you what it does this is exactly the same thing except that I didn’t do the I didn’t do that the other angle bracket there but let me show you what it actually looks like see hopefully I have this up here that’s that lon I do not so let me open it up okay here we go let’s look at vector example oops okay let me push push it down for a minute so here’s here’s what we’ve got here we have ok this is a word list let me see if I can’t make it bigger for you lecture hall how’s that there we go a little bigger it’s a lot bigger actually ok so here’s what we’ve got here we’ve got just a word list and by the way you can grab this off the web page ok if you’re having trouble starting on this assignment right you might want to grab this and see how I’ve set it up because this you might be able to work this right into your right into your program for this week so if you’re having trouble starting this might be a good place ok in here we’ve got a thing that says process word current song or the print song here we go so I’ve written it twice here I’ve said the simple counter method and I’ve act that highlighted out or I’ve got that commented out and then I’ve got the iterator method which is exactly what we had in the previous page here ok it’s going to go through the whole lyrics for a song and print out each one word by word with the little little alligator things on each side right the less than I graded on each side ok watch what happens when I run this oops it’s not going to work because I was doing this on a different computer hold on one sec so what happens when you try to work with two different computers luckily leave I know what I’m doing here ok there’s that and there’s that I’m going to put that in here and now it should work ok there we go ok so here’s what it printed out see hang on there we go ok so here’s the Rick Astley first cry for help it printed all the lyrics right lyric so it said there’s the artist there’s a title and then she’s taking my time convinced me blah blah blah right that’s all the lyrics in a row and it’s I put the little angles here just to show you that’s the end of each word and that reads it in and gives you those individual words and put it into a vector that we then print it out ok go look at the code yourself and and and you’ll be able to see how it works but it’ll it’ll show you the idea and this should actually get you started on like reading the database in if you’re having trouble with that and how to maybe structure it into a song class okay I wanted to give you the ability to do that if you’re if you’re still struggling on how to how to begin there ok questions on the iterator for right now yeah that’s a good question is it like a for each loop it is kind of like a for each loop which we want to explain to the class what a for each loop is yep mm-hmm for each option your list you’re then doing what you want to do with it right it is exactly like that really this is saying the object in this case is the word and the word happens to be of a type a pointer to a vector string right way a rather a string which is the type and so that’s the object and that gob could be anything right it could be the song it could be the lyric it could be that whatever and that’s exactly what it’s doing and then instead of saying oh I’m going to reference it by index you’re referencing by the object so yes it’s it’s a for each is a good way of thinking about it yep good question yes hobby absolutely it’s adding one to the pointer value yeah and it knows so so the compiler knows how big is a is a string like how much memory does it take and it has string string string string string right now this keep in mind it’s not the number of characters that