Solved

generating HTML that depicts C++ code

Posted on 2000-04-04
1
206 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

831 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