CJCoding With Joseph
15free / daySign inCreate account

Capitalize the First Character

Write a function void capitalizeFirst(const string& filename) that opens filename with an fstream in ios::in | ios::out mode, reads its first character with get, moves the write position back to the start with seekp(0), and writes the uppercase version of that character (use toupper from <cctype>) over it with put. Everything else in the file stays exactly as it was. The file always has at least one character.

The test creates the file, calls your function and prints every line of the file. For a file containing hello world it prints the output shown in Expected Output.

Do NOT write a main function.

Expected Output:

Hello world
Zebra crossing
second line

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

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