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
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.