Click here to Skip to main content
15,671,266 members
Articles / Web Development / HTML
Posted 5 Nov 2007


12 bookmarked

CPP to HTML converter

Rate me:
Please Sign up or sign in to vote.
3.22/5 (11 votes)
6 Nov 2007CPOL1 min read
C++ syntax highlighting in HTML format.


Sometimes I need to post C++ code on forums or blogs that don't offer direct support for that. On these sites, the online editor allows you to directly modify the HTML code, but this is not the simplest or most enjoyable thing to do. Because I wanted C++ syntax highlighting so hard, I decided to create a little tool to automate this task as much as possible and to allow me to focus on the real subject.

Using the code

The result is cpptohtml.exe that takes a .cpp file as a command line argument and generates a .html file. If no file name is provided as argument, a standard "file open" dialog allows the user to specify the source .cpp file. The tool also accepts /C as a command line argument that specifies the source code is taken from the clipboard and the HTML result is also put in clipboard.

  • Open your preferred IDE and copy the C++ source code into the clipboard.
  • Launch the tool using the shortcut key combination. The HTML result is available in the clipboard.
  • Paste the formatted HTML in the online blog editor.

Points of interest

The archive also contains a .js script to automate the shortcut creation. I am pretty happy with the final result and how C++, LEX, and JScript is combined to automate a boring repetitive task.


External download link:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior) Codecentrix Software
Romania Romania
Software consultant in Bucharest Romania writing Windows programs and browsers plug-ins since 1998 with Visual C++.

Comments and Discussions

QuestionCan you post the .y yacc file too please Pin
v_srinu_26_f21-Apr-09 4:15
v_srinu_26_f21-Apr-09 4:15 
AnswerRe: Can you post the .y yacc file too please Pin
Adrian Dorache21-Apr-09 6:38
Adrian Dorache21-Apr-09 6:38 
GeneralYet another Source to HTML Tool Pin
MSLeuchtturm6-Nov-07 1:15
MSLeuchtturm6-Nov-07 1:15 
GeneralRe: Yet another Source to HTML Tool Pin
Adrian Dorache6-Nov-07 2:20
Adrian Dorache6-Nov-07 2:20 
GeneralVery nice tool Pin
Paulius Maruka6-Nov-07 1:08
Paulius Maruka6-Nov-07 1:08 
Hey this is very nice and handy tool, but it could be even more useful, if it could convert to BB code so that you can paste the code in phpBB forums (or other forums that allow BB code, but doesn't allow HTML code).

Also, it would be nice if it would allow some level of configuration (it could use CSS with classes for keywords, numbers, strings, comments and so on). If you could change this CSS style, you could add all sorts of effects (bold the keywords, italic for strings etc).

Very nice tool, though! I love it! Smile | :)

"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off." --Bjarne Stroustrup

GeneralRe: Very nice tool Pin
Adrian Dorache6-Nov-07 7:07
Adrian Dorache6-Nov-07 7:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.