Solved

generating HTML that depicts C++ code

Posted on 2000-04-04
1
208 Views
Last Modified: 2011-09-20
Is there a program that generates nicely formatted HTML that depicts C++ code?

i.e. I have a C++ code fragement that looks like:
    void userCode(Fred& x, Fred& y)
    {
      x = y;   // Could be self-assignment if &x == &y
    }
   
And the program should generate the following HTML:
<tt><br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;userCode(Fred&amp;&nbsp;x)<br>
&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;x;&nbsp;&nbsp;&nbsp;</tt><em>//&nbsp;Self-assignment</em><tt><br>
&nbsp;&nbsp;&nbsp;&nbsp;}
</tt>

I suppose the main issues is you have to force spaces (&nbsp) for all indents and do a line break (<br>) for each line.

If anyone knows of a utility that is already out there, it would be most helpful.
0
Comment
Question by:VEngineer
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 2686417
Simply embrace the C++ code with the <pre> HTML tag.

<pre>
void userCode(Fred& x, Fred& y)
{
    x = y;   // Could be self-assignment if &x == &y
}
</pre>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Grammars for C C++ and java 1 138
IdTCPClient1->Disconnect(); not working 3 86
SNMP error No Such Object available on this agent at this OID 3 370
Need some help with mailto 16 31
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question