I have a program in which I read (using ifstream) words from a file into a vector word objects - The word is stored (as a string) as well as a few other attributes about the word in the file.
Could someone point me in the right direction of how to sort this vector by the word names alphabetically?
I've seen the equivalent done with arrays when using the algorithm package and the sort function. Is this possible using vectors as I've described?
Could you be more specific about what you are storing? That way we not only point you in the right direction but also validate your design, as well.
For example, if you only wanted a sorted list of strings (words), you could just put them in a set<string> which would be sorted automatically.
Another example would be if you wanted to count the number of words in a file by storing a string and a single attribute (count), you could use a map.
From what you described it sounds like you could have a Word class that defines the < operator (so that STL containers can use it to sort items) and store those in a set<Word>. Here's a sloppy attempt to do this: