Put your code in code tags

If you post code on this forum, put your code in code tags.

If you already pasted some code without using code tags, go back and edit your post and put code tags in!

It's very hard to read code that isn't in code tags! Help us help you by making your code easier to read and follow!

It's very simple:

[code]
paste your code here
[/code]


This:

int main()
{
int myvar = 15;
cout << myvar;
return 0;
}


Becomes this:
1
2
3
4
5
6
int main()
{
    int myvar = 15;
    cout << myvar;
    return 0;
}


Much nicer, isn't it?

Notice the added benefit of line numbers so we can easily point out which line of code has the problem in it.


-----------------------------------------

I created this article because I find myself telling many people to use code tags a lot. Sometimes I find myself telling it to the same person multiple times. With an article here now I can just link them to this.
Using code tags alone isn't enough. Most programs are more complex than the example that was presented. You have to beautify the code in your code editor first. The code tags will not indent for you. It is also better to avoid using tabs. Use 3 or 4 spaces in place of tabs. Inconsistent tabbing causes all kinds of problems. It doesn't do much good to put the code within tags if it is difficult to understand the nested programming structures and loops.
closed account (S6k9GNh0)
I actually use a code beautifier to do the work for me. Code::Blocks has one built in though if I'm ever using one.
Bravo! Well said. Code without tags should be torn off the forum and thrown into a fiery pit.
Yeah, someone should write an article on indenting your code...ugh, the horrors of stuff like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
    int i, j, k;
    cin>>i>>j>>k;
    if(i == 2)
{
    j *= 2;
}
else k += 2;
if(j %= 5)
    {
        j = 55;
            }
                return 0;
}
This is a style that irks me:
1
2
3
4
int main()
{some_code;
    some_code;
    some_code;}
Disch wrote:
I created this article because I find myself telling many people to use code tags a lot. Sometimes I find myself telling it to the same person multiple times. With an article here now I can just link them to this.


This is an article subject that has been that has been posted about on a few occasions:
http://www.cplusplus.com/forum/articles/9044/#msg41810
http://www.cplusplus.com/forum/articles/1624/#msg5695

Unfortunately, they don't get read and you have to either tell people how to put code in tags or point them to one of the posts about it.
firedraco wrote:
Yeah, someone should write an article on indenting your code..


Work in progress:
http://www.cplusplus.com/articles/preview/20/
either code tags, or pastebin.com. pastebin by far is really easy, as a matter of fact they both are really easy.

Pastebin ------> "http://www.pastebin.com"
Topic archived. No new replies allowed.