word sort

I have a homework assignment and I can't figure it out.. new to c++

You are given a series of words separated by spaces, and ending with a . Your output should be those words sorted lexicographically, like a dictionary. You should do this using the string object's .compare function. There may be several lines of words; your program should repeat this for each line and stop when it reaches a line with a single word.

Sample input:

i am sam .
i do not like green eggs and ham .
sam .

Sample output:

am i sam
and do eggs green ham i like not
sam

Note: watch out for white space. The words are separated by spaces, and there is a space at the end of each line as well as a newline at the end.

Hint: use cin to read in words and store them in a string array. Use bubble sort or insertion sort (google them) to reorder them.

Topic archived. No new replies allowed.