HTML files use tags enclosed in angle brackets to denote formatting instructions. For example, <B> indicates bold and <I> indicates italics. If a web browser is displaying an HTML document that contains < or > , it may mistake these symbols for tags. This is a common problem with C++ files, which contain many < ’s and > ’s. For example, the line "#include <iostream>" may result in the browser interpreting <iostream> as a tag.
To avoid this problem, HTML uses special symbols to denote < and > . The < symbol is created with the string < while the > symbol is created with the string > .
Write a program that reads in a C++ source file and converts all < symbols to & It; and all > symbols to & gt;. Also add the tag <PRE> to the beginning of the file and </PRE> to the end of the file. This tag preserves whitespace and formatting in the HTML document. Your program should output the HTML file to disk.
As an example, given the following input file,
#include <iostream>
int main()
{
int x=4;
if (x < 3) x++;
cout << x << endl;
}
the program should produce a text file with the following contents:
<PRE>
#include <iostream>
int main()
{
int x=4;
if (x < 3) x++;
cout << x << endl;
}
</PRE>
You can test your output file by opening it with a web browser. The contents should appear identical to the original source code.
Sorry the answer is not available at the moment…
If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.
Spread the 'tradition of sharing'.