How can I make a vector of string while reading from a file?

Hey guys. I am trying to read in words from a file, and I want each one to be an element of a vector. For example, if the file contains 3 words: red, white, blue (in that order), I want vector[0] = red, vector[1] = white, vector[2] = blue. How can I do this? Thanks!

BTW, the file looks like:
red
white
blue

And I want my output to be like:
cout << vector[1] // Displays white to the console
Hi!

Do you know how to read in from files? If not...
http://cplusplus.com/doc/tutorial/files/

From there, I'm assuming you know about loops and vectors' push_back() function. What you could do is read each line into a temporary string variable (using a loop and getline(cin, string)) and push/*it*/_back(string) into the vector.

-Albatross
Topic archived. No new replies allowed.