Published by
Mar 30, 2013 (last update: Mar 30, 2013)

How to use code tags

Score: 4.3/5 (60 votes)
*****
This article describes how to use code tags in posts on forums of this site.

Code tags color code and add line numbers just like modern IDEs do.

1
2
3
4
5
6
7
8
9
#include<iostream>
using namespace std;
//This is a very simple program

int main()
{
	cout<<"Hello World"<<endl;
	return 0;
}

Intended audience:

This article is mainly for users who are new to this site and don't know about the 'code tag' feature of this site. New users are advised to read the full article and not just a part of it.

This article is also for users who are fed up of people asking for help without showing their code in code tags. Just paste a link to this article as reply. I haven't included details like altering line numbers or showing output with the code to make it simple for beginners. If you want to know details, click here.

How to use code tags?

Let me explain this with an example. Suppose you are posting on this forum. You would see something like this



After writing out your problem, you should use the preview button to see how your post looks. You would get this:



This post has not used code tags and looks unpleasant to the eyes.

To use code tags select your post and press the format code button:



This will cause [code]...[/code] to appear automatically around your code.



You could also have manually typed [code][/code] around your code. It's the same thing.
Now clicking on the preview button, we find that the output looks like this:



Mission accomplished.

If you have already posted without code tags, you can click on the button on your post and edit your post.



Caution:

The code tags will not indent your post. You have to do it manually. The best way is to write code in your IDE and simply paste it in your post. If you don't use an IDE, you can manually add spaces to indent your code.