October 1999
Beginner
304 pages
7h 11m
English
Using your favorite editor, type two or more lines of text into a file. Write a program to open the file, reading each word into a vector<string> object. Iterate over the vector, displaying it to cout. That done, sort the words using the sort() generic algorithm.
#include <algorithm> sort( container.begin(), container.end() );
Then print the sorted words to an output file.
I open both the input and the output file before reading in and sorting the text. I could wait to open the output file, but what would happen if for some reason the output file failed to open? Then all the computations would have been for nothing. (The file paths are hard-coded and reflect Windows conventions. The algorithm header file contains the forward declaration ...
Read now
Unlock full access