CPlusPlus Syntax Highlighting

Hello,
I'm wondering if its possible to format code so that it looks exactly like the formatted code when posting on this website using the code brackets. I want to have it in a word document and I like the way it is formatted here.
It wouldn't be beneficial in anyway. Most people who spend any time with their IDE individualize it's appearance. If you want an exact replica maybe a mosaic of screenshots would do the trick? That sounds like a lot of work to me though for very little added functionality.
I just meant the way its formatted when you put code snippets on here. You use the code block.
I mean pasting the code in here, previewing it, then copying it works. But I was just wondering if there was something else that would produce the same results.
I don't know what you mean. Do you mean you want a program that reads in your source code and formats it for you? If so, try AStyle. It comes with the CodeBlocks IDE. There is also GNU Indent but I don't like it. It's buggy and it has stupid default settings. One time, in my naivety, I ran Indent on my entire Projects folder and it broke a bunch of files. Luckily it makes backups.
Do you mean the colours that code has inside code blocks?
He said word document, so I think he means to have the code in MS Word/MS Office/LibreOffice/etc. look like:

1
2
3
4
5
6
7
8
9
10
#include <iostream>

/* Maybe something like this */

int main(int argc, char **argv)
{
      std::cout << "Just guessing\n";
      
      return 0;
}
Last edited on
I honestly think you should not, never ever ever, use a owrd-processing program to program with.'

That's my opinion, but it's entirely up to you. If you want your code to be automatically indented when you press enter, etc... and color-coded for read-ability, find an IDE (intigrated developement environment) or a text editor that is specifically tailored to programming with (like Sublim Text, or Notepad++, etc...).
@IWishIKnew
I agree because if you don't know what you are doing you may end up saving the file as something other than plain text causing it to not compile. Though, I wonder if he is using a word processing program to turn in code to an instructor and just wants it to be formatted like the above when turning it in.
Yes he wants the highlighting in word document.

I have no idea on how to do that but there is this great text editor that is fully customisable, its called sublime 2. I use it, its great.
The this I like most about it is that it gives you an option to save when you click on another window/program. So when I click on Terminal, it saves and I dont have to press ctrl+s.
BHX That is exaclty what I want, I found
http://alexgorbatchev.com/SyntaxHighlighter/
That basically does it, except I cant figure out how to use it without actually inserting my code between the <pre> tags in the file.

IWishIKnew I would never use them to program either, I use visual studio and code blocks, but I was just wondering if there was a program already written that would take in source code, that normally cannot just be copied and pasted into word preserving the formatting, and format it, then all you need to do is copy and paste the snippet. I like the way the code is formatted here and using the highlighter I linked.

If you take a look at it and can think of a way to get it working where you paste your code into a textarea and it then automatically formats it and shows underneath that would be awesome. Also, thanks for the links to the other possible solutions!
well... you could just modify your ide to match the colors you see here by sight. It might not e accurate, but it will get the job done.
True, but I dont think copying and pasting from an ide copies line numbers does it?
Topic archived. No new replies allowed.