Sign In

    Enjoy FOSSwire's content? Have it delivered! Subscribe

    Basic C++ Tutorial

    We'd like to give our new category, Programming, a bit of love. So, we're going to have some C++ tutorials from the ground-up, starting with your classic Hello World.

    This tutorial should work on any system with a C++ compiler. For Windows, try Dev-C++. Ubuntu and Debian users, install the package build-essential. Fire up your text editor or IDE and let's get going. The rest of this tutorial will be in the code comments (marked by /* */ and //) below; while you can copy them into your compiler if you want, they are not necessary.

    I recommend manually typing in the code above, line by line (excluding the comments). This makes sure you are able to learn by doing and not just by seeing. Save the file you just wrote as test.cpp and then open a terminal (unless you are using Dev-C++, in which this can be accomplished by hitting Compile).

    g++ -o test test.cpp

    This invokes the compiler using the file test.cpp and outputs it as a test binary. To run your newly-made program:

    ./test

    If it didn't compile correctly, check your error messages and look for common mistakes, such as a missing quote or semicolon. If it did work, congratulations! You've just written your very first C++ program. Subscribe to the Programming section for more tutorials like these in the future.


    Avatar for jacob Jacob Peddicord - http://jacob.peddicord.net/

    Jacob is a web developer, student, and programmer from Ohio. He is a staff member at the Ubuntu Forums and is most likely a fanboy of the distribution. He loves to write in code and words, play video games, and rant about topics most would have abandoned long ago. Jacob uses GNOME and is never seen running stable software, much to the demise of his laptop.


    Tagged in

    • FSDaily

    Home » Articles »

    Discussion: Basic C++ Tutorial

    1. # Posted on 01 November 2007 at 09:52 PM

      [...] came across an article on FOSSwire on beginning to program in C++. Decided to give it a try, their first tutorial was [...]

       

    2. kafuka (guest)

      # Posted on 03 November 2008 at 04:37 AM

      Thanks Helped me make the transition to linux for C++

       

    Did you like this article? Want to help write the content that makes FOSSwire great? Submit your own article and get it reviewed by other members.

    Home » Articles » Basic C++ Tutorial