Save a Person
easyQuestion 604Write 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, so print one after the last line.
Hints2 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.