CJCoding With Joseph
15free / daySign inCreate account

Largest Number in a File

A text file contains one or more integers separated by spaces or newlines, for example:

12 91 5 44

Write a function int maxInFile(const string& filename) that opens the file, reads every integer with >> and returns the largest one. The file always contains at least one number, and numbers may be negative.

The test prints the returned value on its own line, for example (see Expected Output).

Do NOT write a main function.

Expected Output:

91
-3

= 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.