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;
}
|
|
|
Namespace
using namespace <namespace-name>; |
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 |
|