C++: Read individual lines from text file, sort words alphabetically
I've created a text file with 3 lines filled with random words. I want to :
Read each line in the file individually.
Sort the words in each line alphabetically
Output the sorted line to console.
This is what I've come up with so far [runnable]:
https://gist.github.com/anonymous/6211515
It reads the lines and puts them inside a vector, sorts that vector and
then prints the resulting vector to console. But I'm just sorting the
lines, I'm not sorting the actual lines. I'm inputting the entire line as
a string, which is causing my problems. I'm very new to C++ programming
and I'm not sure what I should do to be able to sort the actual words, not
the lines.
This is not homework, it's just a problem that was suggested to me that I
solve in preparation for an upcoming exam.
No comments:
Post a Comment