I have a program that is similar to what you are truing to do.
I started be taking an exiting .html file and breaking it into sections, i.e., and opening and end section. The program would open the opening part and a while using std::getline" would read the input file and write it to the output file. This gives me everything from the first line of the .html file to the opening "<body> tag.
The middle part of the .html file is a table generated by the program.
When that is finished the "end" file is read and written to the output file finishing the .html code.
The last section of the .html file is java script code created by the program and written to the output file.
This gives me one complete .html file ready to use.