CJCoding With Joseph
15free / daySign inCreate account

Save a Person

Write a function void savePerson(const string& filename, const string& name, int age) that opens filename with an ofstream (the starter does this as out) and writes two lines: Name: followed by a space and the name, then Age: followed by a space and the age. Each line ends with a newline. For savePerson("person_a.txt", "Bob", 30) 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:

Name: Bob
Age: 30
Name: Ann
Age: 7

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

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