Cpp Cheat Sheet Expanded
Cpp Cheat Sheet Expanded
1. Basic Syntax
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
2. Data Types
3. Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
== Equal to
!= Not equal to
>= Greater than or equal to
<= Less than or equal to
4. Control Statements
if (condition) {
Java Cheat Sheet
// code block
} else {
// another code block
}
switch(expression) {
case value1:
// code
break;
default:
// code
}
5. Loops
while (condition) {
// loop body
}
6. Functions
class Animal {
public:
string name;
void makeSound() {
cout << "Sound" << endl;
Java Cheat Sheet
}
};
class Dog : public Animal {
public:
void makeSound() {
cout << "Bark" << endl;
}
};
8. Exception Handling
try {
int x = 10 / 0;
} catch (exception &e) {
cout << "Error: " << e.what() << endl;
}
9. File Handling
#include <fstream>
ofstream file("file.txt");
file << "Hello, C++";
file.close();