When we are working on the homepage, we sometimes need to convert the TXT file into an HTM file. In fact, we can write a small ProgramTo convert the TXT file into an HTM file. Here, we use VC to write this program. First, create a new dialog box program, and then add two text boxes and one button in the dialog box, use classwizard to connect two text boxes with two variables. These two variables are in the cstring class. One variable is m_txt, indicating the path and file name of the TXT file to be converted, and the other is m_htm, which is used to store the path and file name of the converted HTM file.
Then add the button control and clickCodeAs follows:
Updatedatatrue
Cstdiofile srcfile
Srcfile. openm_txtcfilemoderead
// Put the contents of the TXT file to be converted into the strtemp variable through the cstdiofile class
Cstring strtemp
Srcfile. readstringstrtemp
Srcfile. Close
Cstdiofile FF
Ff. openm_htmcfilemodecreate | cfilemodereadwrite
Ff. writestring ″″
// Put the strtemp content in the file pointed out by the m_htm variable, add the HTM file header, and the file name must be
// End with htm
Ff. writestringstrtemp
Ff. writestring ″″
Ff. Close
Afxmessagebox "converted successfully ″
This program is successfully debugged in window2000 and vc6.0.