← Back to Streams
Question 652
File Size with seekg/tellg
File Size with seekg/tellg
Write a functionlong fileSize(const string& filename)that opensfilenamewith anfstreaminios::in | ios::binarymode (the open is already written for you), seeks to the end withseekg(0, ios::end), and returnstellg()cast tolong. The test creates the file, calls your function and prints the result on its own line. For a file containing exactly the eleven charactershello 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
Sign in to use hintsTopics:
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.