Homework 36: C++ I/O, string, and vectors
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Monday, April 24
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw36and submit using the204subcommand. - This is an electronic homework and you do not need to print out anything to turn in during class.
Assignment
- Required reading: Sections 6 (I/O) and 7 (String and Vector) from the Unit 10 notes.
-
Write a C++ program called
longword.cppthat reads in strings until the user types "STOP", and then reports the longest string that was entered.You should use the C++ libraries
<iostream>,<string>, and<vector>, and must not use any of that old C stuff likescanfor char arrays. (Note, it is possible to solve this problem without using any arrays or vectors, but I really want you to use a vector of strings anyway to get the practice.)Example runs:
roche@ubuntu$./longwordEnter words and then STOP:hello darkness my old friend STOPThe longest word is darknessroche@ubuntu$./longwordEnter words and then STOP:i've come to talk with you again STOPThe longest word is again