CJCoding With Joseph
15free / daySign inCreate account

Longest Line

Write a function string 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 returns strawberry.

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
Topics:
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.