CJCoding With Joseph
15free / daySign inCreate account

File Size with seekg/tellg

Write a function long fileSize(const string& filename) that opens filename with an fstream in ios::in | ios::binary mode (the open is already written for you), seeks to the end with seekg(0, ios::end), and returns tellg() cast to long.

The test creates the file, calls your function and prints the result on its own line. For a file containing exactly the eleven characters hello world (no newline) it prints the output shown in Expected Output.

Do NOT write a main function.

Expected Output:

11
0

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Streamsfstream
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.