← Back to Streams
Question 589
Longest Line
Longest Line
Write a functionstring longestLine(const string& filename)that returns the line of the file with the most characters. If several lines tie for the longest, return the one that appears first in the file. For a file containing: kiwi strawberry fig the function returnsstrawberry. The test prints the returned line on its own line, for example (see Expected Output). Do NOT write a main function.
Expected Output:
strawberry apple
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsifstream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.