Show Menu
Cheatography

C++ Starter Sheet Cheat Sheet (DRAFT) by

C++ Starter Cheat Sheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Hello World!

#include <iostream> // load IO objects (cin, cout)

using namespace std;

int main() {
    // prints the string enclosed in double quotes
    cout << "Hello World!";
    return 0;
}

Postive or negative?

// Program to print positive number entered by the user
// If the user enters a negative number, it is skipped

#include <iostream> // load IO objects (cin, cout)
using namespace std;

int main() {

  int number;

  cout << "Enter an integer: ";
  cin >> number;

  // checks if the number is positive
  if (number > 0) {
    cout << "You entered a positive integer: " << number << endl;
  }

  cout << "This statement is always executed.";

  return 0;
}
 

Include

#include <fi­le-­nam­e>

Namespace

using namespace <na­mes­pac­e-n­ame­>;

Input/­Output

Keyword
Example
Cin
cin >> number;
Cout
cout << "­Enter an integer: ";

Data Types

Keyword
Example
int
0
float
3.0f
double
3.0
char
'a'
string
"­Hello World!­"
bool
true

Operators

Operator
Usage
+
Add
*
Multiply
-
Minus
/
Divide
=
Assign