Show Menu
Cheatography

C++ 1: Syntax and Searching Cheat Sheet (DRAFT) by

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

Basic Code Template

#include <bits/stdc++.h>
using namespace std;

// Main Function 
int main() {
    //Write code to run here
    return 0;
}

Comments

// Line comments
// Put comment here

/*
Block Comments
Put entire sections of text
in here
*/
 

Input Output

Type
Code
Input
cin >> Var1 >> Var2 >> ......;
Inputs of variables can be separated by spaces, tabs or newlines. eg. "1 2 3"
Output
cout << Data1 << Data2 <<...;
Remember to put spaces and endl to output data in the approp­riate format
Output newline
cout << endl;
 

Data types

Integers
short
-215 to 2^15-1 (about 32 000)
int
-231 to 2^31-1 (about 2.14 × 109 )
long long
-263 to 2^63-1 (about 9 × 1018)
unsigned short
0 to 2^16-1 (about 65 000)
unsigned int
0 to 2^32-1 (about 4.29 × 109 )
unsigned long long
0 to 2^64-1 (about 18 ×1018)
Floating Point
float
floating point
double
more precise floating point
long double
even more precise
string
used to store text

Declaring variables

// One item
data_type variable_name; //initial value is garbage
variable_name = value;
// OR
data_type variable_name = initial_value;

// Array
data_type array[length]; //initial value is garbage
array[index] = value;
// OR
data_type array[length] = {value1, value2, ....};