← Back to Streams
Question 662
Capitalize the First Character
Capitalize the First Character
Write a functionvoid capitalizeFirst(const string& filename)that opensfilenamewith anfstreaminios::in | ios::outmode, reads its first character withget, moves the write position back to the start withseekp(0), and writes the uppercase version of that character (usetoupperfrom<cctype>) over it withput. 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 containinghello worldit 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
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.