Learning materials

C++ programming language

On this page

A high-level compiled, typed, object-oriented, class-based, and general purpose programming language.

Naming convention required in class

We use a common naming convention in the class:

  • Type, class/struct, and template names: UpperCamelCase (Pascal case)
  • Function, variable names: lowerCamelCase
  • Constant/Macro names: ALL_UPPER_CASE_WITH_UNDERSCORE
  • Header file extension: hpp
  • Source code file extension: cpp
  • File names: all-lowercase-with-hyphen.cpp

Compilation Requirement in Class

In this course, we stick to the C++14 standard for consistency. Always add -std=c++14 flag to the g++ commands during compilation.

Best practices in C++

There are some great guidelines on how to code correct and efficient programs in C++.

Type of Errors

Three types of errors for C++ as a typical compiled programming language:

Syntax error
Also known as compilation error. It will be identified by the compiler and will stop the compilation process. Any program with syntax errors cannot be compiled.
Runtime error
Errors that abort a compiled program during its runtime. Any program with runtime errors can be compiled but will abort when it is executed.
Logic error
Errors that cause a program to provide unexpected outcome. Any program with logic errors can compile and run but fail to give the correct outcome.

Hello World in C++

#include <iostream>   // to include a system header to enable input/output
#include <string>   // to include a system header to enable string type
using namespace std;  // to avoid typing std:: in front of many common keywords

int main() {
  string name;  // string variable called name
  cout << "What is your name? (use one word) "; // display to the screen
  cin >> name;  // read from keyboard input
  cout << "Hello " << name << " " << endl;

  return 0;  // 0 means success, better use EXIT_SUCCESS constant
}