how to convert at txt file to html

i am trying to write a program that reads a txt file and converts it into html 1.0 file.

The header html file should start with the following structure:


outfile2 << "<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en">
<head>
<meta http - equiv = "Content-Type" content = "text/html; charset=UTF-8" / >
<title>Test< / title>
< / head>
<body>" ;


for some reason when i combine it with outfile2 it gives me user defined literal operator not found.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <fstream>
#include <iostream>
# include <sstream>  // for getline

using namespace std;

int main() {

	char data[100];

	char ch;

	int  ctr =  0 ;

	string line;

	
	ofstream outfile2;
	outfile2.open("plato.html");



	// open a file in read mode.
	ifstream infile;
	infile.open("plato.txt");

	cout << "Reading from the file" << endl;
	//infile >> data;

	

	// gets every single char 




	outfile2 << "<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en">
		<head>
		<meta http - equiv = "Content-Type" content = "text/html; charset=UTF-8" / >
		<title> Test< / title>
		< / head>
		<body>" ; 




	while (infile.get(ch))
	{
		/*cout << ch;*/

		if (ch != '\n')
		{
			outfile2 << ch;

		}

		else if( ch == '\n' )
		{

			outfile2 << "<br />" ;

			outfile2 << ch; 

			++ctr; 

		}


	}



		outfile2 << "< / body>" << endl << "< / html>" ;
	

	cout << "number of lines is " << ctr << endl; 



	// close the opened file.
	infile.close();


	system("pause");

	return 0;
} 
Last edited on
You need to escape the " inside other " with \", for example
"She said: \"Bla Bla\"";
Also, only raw string literals may contain newlines. Inside a string, newline characters are written \n.
Hello masterinex,

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.

Hope that gives you some ideas,

Andy
Topic archived. No new replies allowed.