Squares Table
mediumQuestion 608Write a function void writeSquares(const string& filename, int n) that opens filename with an ofstream and writes one line for every integer k from 1 to n (n is always at least 1). Each line holds k, a single space, and k*k, followed by a newline. For writeSquares("squares_a.txt", 3) the file must contain exactly (see Expected Output).
The test reopens the file and prints every line, so that is also the output.
Do NOT write a main function.
Expected output
1 1 2 4 3 9 1 1 2 4 3 9 4 16 5 25
= newline. The output ends with a newline, so print one after the last line.
Hints3 available
Sign in to use hintsTopics
Streamsofstream
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.