Question: 1 Goals 1. To read C++ strings from a file 2. To use C++ input and output. 3. To use a vector of strings 4.
1 Goals 1. To read C++ strings from a file 2. To use C++ input and output. 3. To use a vector of strings 4. To handle end-of-file correctly. 5. To use the built-in sort function to sort a vector. The Little Brown Dog. This assignment covers the chapter on streams and files. It is the last program you will write that is entirely in one file. 1. Include the header file named tools.hpp. It will include all other headers you need. 2. Print a title on the first line of the output: P2: Little Brown Dog. Print your name or names on the second line of the output and leave a blank line after that. 3. Open an ifstream on the file p2-BrownDog.txt. 4. If the file did not open correctly, give a clear error comment that includes the name of the file, then abort execution. 5. Instantiate a vector of strings. A vector will grow as long as it needs to be to contain all your input. I will call it vin this description. 6. Read a series of strings from the input stream. For each one, read the entire line up to, but not including, the newline character. 7. Insert each string into vusing v.push_back(). 8. When end-of-file occurs, sort the strings using the built-in sort algorithm. Here is the correct syntax: sort (v.begin(), v.end()); 9. Then print the sorted strings. Print each string on a separate line. Testing and Output. Look at the last line of the input file, then look at your output. That line should be in the output exactly once. If it is there zero times, or twice, you are handling the end-of-file wrong. Copy the output into a comment at the end of main, or into a .txt file and submit the output with your .cpp file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
