Search

LearnCpp.com tutorials: Now with syntax highlighting!

Yup, it’s finally here. If you have a javascript enabled browser, code examples in the tutorials will now have line numbering and syntax highlighting. For example, instead of:

Cents& Cents::operator= (const Cents &cSource)
{
    // check for self-assignment by comparing the address of the
    // implicit object and the parameter
    if (this == &cSource)
        return *this;
 
    // do the copy
    m_nCents = cSource.m_nCents;
 
    // return the existing object
    return *this;
}

you will now see:

I am still working at converting the previous tutorials from the old-style to the new-style, and given that there are over 100 of them, it may take me a little while to get through all of them.

If you try to mouse-select the syntax-highlighted code and paste it into another document (or compiler), you will also get line numbers. Instead, use the “copy to clipboard” function at the top of the code snippet. This will place the code in your clipboard, and you can paste it into another document like normal.

If that doesn’t work for you, use “view plain”, which will show you the code without syntax highlighting and line numbers, and copy it from there in the normal manner.

I hope you find that this change brings some added value to your CPP experience.

Thanks for stopping by.

-Alex

2 comments to LearnCpp.com tutorials: Now with syntax highlighting!

  • Its a pity the very first tutorials are not highlighted like this, thats fantastic đŸ™‚

    [ All of the old chapters have now been similarly highlighted. -Alex ]

  • Zak

    I wish I read this earlier. Every time I copied code(which I tried doing as little as possible), I would have to delete the numbers. I was going to complain that it is hard to copy the code. However after reading this, I realized that I should do copy to clipboard.

    Thanks a lot. AND BTW I LOVE THE TUTORIAL.

Leave a Comment

Put C++ code inside [code][/code] tags to use the syntax highlighter