C++ Notes

C++ Reference

Integrated Development Environments (IDE)

While different students will use different machines (PC/Mac/Linux) and different IDEs, in order to get credit your program must run in the environment used for grading, indicated by the instructor. Be sure to leave time to test your program in the environment used for grading, since there are differences between assumptions made and automatically included libraries between different IDEs.

  • Everyone (Windows / Mac / Linux):

    • JetBrains' CLion IDE offers the CLion development environment free to all students. See https://www.jetbrains.com/student/. CLion includes a nice debugger. There are two major parts to the installation:

      1. After creating a JetBrains Academic account, download and install the product you want (CLion in this case). After installation when you first run it you'll be prompted to enter your JetBrains account information, which will allow you to use it free for a year, at which point you can renew it and keep using it as an academic user.

        1. Download and install a compiler to use with CLion, MinGW in this case. See this YouTube installation video, and in particular pay attention at 2:43 to the details on how you must also install the compiler.

      • Code::Blocks There have been some problems with running the debugger on the Mac version, which hasn't been updated since 2013.

    • PC Users:

    • DevC++ is a small relatively easy to use Windows IDE. The original version (DevC++) is a bit dated, so you should probably use the more recent Embarcadero version. The debugger is sometimes a bit flaky, so towards the end of the semester you will want to transition to a more robust program (e.g. JetBrains' CLion or Microsoft Visual Studio Community version).

      • To enable C++11 in DevC++go to menu option:

      • Tools / Compiler Options / Programs

      • and update the fields next to gcc and g++ to also have: -std=c++11

      • For example: gcc.exe -std=c++11

      • Microsoft's Visual Studio Community is a free download and gives you a very robust IDE. You can also download the full version of Visual Studio from the UIC Web Store. See Prof. Hummel's tutorial on getting started with the full version of Visual Studio.

      • Here are some older tutorials:

        1. See this tutorial, and also Bob Hahurst's guide to getting started with Visual Studio.

        2. When creating a project be sure to uncheck the box that says "include precompiled headers," otherwise you will end up needing a Microsoft-specific line at the top of your code (#include "stdafx.h") which will cause an error when being graded elsewhere. Visual Studio (in C) wants you to use the Microsoft "scanf_s" instead of standard "scanf". To disable this, put this at the beginning of your progam:

        3. Newer Versions:

        4. #pragma warning(disable:4996)

        5. Older Versions:

        6. #define _CRT_SECURE_NO_WARNINGS

        7. Or from the Project menu select: "project_name" Properties -> C/C++ -> SDL checks -> No (/sdl-)

    • Mac Users:

Programming in the Cloud

  • VS Code is a wildly popular cross-platform editor and (I'm told) allows collaboration

  • repl.it

  • codepad.org. For instance see this example. Note that you can't read from files or handle user input.

  • ideone.com, which does allow for user input, though it is awkward. It allows 1,000 free submissions/month.

  • Google Collab allows you to create and run code in the cloud as a Jupyter Notebook, such as this example.

For online collaboration tools, to find the latest I suggest doing a google search using: online programming collaboration tools free

Debugging

As your programs become more complex, using a debugger is essential to quickly finding bugs in code. See the following guides [Thanks to Abhinav Kumar]:

Pretty Printer

If your IDE does not have an option to automatically format your C code, then you can use this tool online

To get syntax highlighting with line numbers that you can use copy/paste into Word, copy/past your code into planetb.ca/syntax-highlight-word and from there copy/paste it into Word or OneNote.

To get syntax highlighting with line numbers and generate HTML try hilite.me

Posting Sample Code

Want to share some code by pasting it somewhere accessible online? Use:

    • pastebin The original (as far as I know)

    • dpaste [thanks to Desiree Galewski]

Free Books

If you are just starting out with C++, see Mark Mahony's Animated Introduction to Programming in C++

For UIC students the library has free access to the online Safari CS books which includes Java and C++ programming books. I suggest:

Programming in C, Third Edition, by Stephen Kochan

C++ How to Program, 6th Edition, by Deitels

Also see UIC's online Lynda video training modules, with many C++ offerings.

For everyone:

Programming in C++ by Eric Roberts (2012 edition)

Also see this list of freely available programming books. I suggest Thinking in C++ by Bruce Eckel, available for download here.

Learning C++ after Java:

If covering this material after Java, See the MS Word document highlighting the difference between Java and C, and also this brief "Hello World" example for I/O in both C and C++.

See also a crash course in C++ for Java Programmers. (resource accompanying Horstmann's book "Big Java"

UNIX Reference

Testing

Knowledge in software testing is one of the skills many employers ask for from graduating students. What does this mean in practical terms?

Explore this on the testing page, learning about equivalency and boundary tests, with a hands-on exercise to test your skills.

Other

Topics

Download the C++.zip file with all the content in it for the C++ topics shown below. After unpacking that zip file, select the index.htm file to get started browsing the content.

See the corresponding handout

The above linked examples serve as an introduction to variables, assignment, commenting, indenting, operations, and sanity checks.

    • Same simple program in C and in C++. Alternatively see both on the same page: aligned for comparison (MS Word or pdf), syntax highlighted in color (pdf)

(see also textbook example of static members and vectors)

See this handout, from a previous class, that has content beyond what is appropriate for CS 141