http://www.cplusplus.com/articles/N6vU7k9E/
So I've been working through this program. Been getting it set up and ready to go all day. I have a file with a bunch of different names for the bunnies, I'm just not sure how to get a specific line, or more of a random line from my file. Let's say I have one name per line, with 40 names, is there a function I can use to get a specific line, defined by a random number? I guess I'll also need a way to get the number of lines before hand, so I dont generate a random number that would be eof
I have a file with a bunch of different names for the bunnies, I'm just not sure how to get a specific line, or more of a random line from my file.
You could read the whole file, placing each name into a vector. So, after reading a file with 40 names, you should have a vector with 40 names in it (you could use std::strings). You can limit your random number to the possible indexes into your vector.
Ok, well right now I have this being done in my class, I feel like thats bad though. It means everytime a new object is made, this file is gonna be opened up, read into a vector, and closed. But I'm not sure where else to put this.
Ooh push_back() would be much better.
Now how I read one line into one element, the next line into next element, and so on. Not sure how to go about changing lines with this