Numbered Append
mediumQuestion 661Write a function void appendNumbered(const string& filename, const string& msg) that appends a numbered line: the number is one more than the number of lines the file already contains, so the first message becomes 1. msg, the next 2. msg, and so on (a period and a single space between the number and the message).
Open the file in ios::in mode and count its lines with getline (a missing file counts as 0 lines); then open it in ios::out | ios::app mode and write the new line followed by a newline.
The test starts with an empty file, calls appendNumbered("log_a.txt", "boot"), then the same with "run", then "stop", and prints every line of the file (see Expected Output).
Do NOT write a main function.
Expected output
1. boot 2. run 3. stop 1. init 2. ready
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...