Game Leaks

c++ cheatsheet

Submitted by 2UG21CS134, , Thread ID: 278917

2UG21CS134
Lurker
Level:
0
Reputation:
0
Posts:
6
Likes:
0
Credits:
0
09-11-2023, 11:15 AM
#1
// C++ Cheatsheet

// Include necessary headers
#include <iostream>
#include <vector>
#include <string>

// Define namespaces
using namespace std;

// Main function
int main() {
// Output to the console
cout << "Hello, World!" << endl;

// Variables
int num = 42;
double pi = 3.14159;
string text = "C++";

// Input from the console
cin >> num;

// Basic control structures
if (condition) {
// Code to execute if condition is true
} else {
// Code to execute if condition is false
}

while (condition) {
// Loop code
}

for (int i = 0; i < 10; i++) {
// Loop code
}

// Data containers
vector<int> numbers;
numbers.push_back(1);
numbers.pop_back();

// Functions
int add(int a, int b) {
return a + b;
}

// Pointers and References
int x = 10;
int* ptr = &x; // Pointer
int& ref = x; // Reference

// Classes and Objects
class MyClass {
public:
int data;
void method() {
// Member function
}
};
MyClass obj;
obj.data = 42;

// Inheritance
class DerivedClass : public BaseClass {
// Derived class definition
};

// File I/O
ofstream outputFile("file.txt");
ifstream inputFile("file.txt");
outputFile << "Write to file";
inputFile >> text;

// Exception Handling
try {
// Code that may throw an exception
} catch (exceptionType& e) {
// Handle the exception
}

// Standard Template Library (STL)
#include <vector>
#include <map>
#include <algorithm>

vector<int> v = {3, 1, 2};
sort(v.begin(), v.end());

map<string, int> m;
m["one"] = 1;

// C++ Standard Library
#include <string>
#include <iostream>
#include <vector>
#include <map>

// Memory Management
int* p = new int[10];
delete[] p;

return 0;
}

RE: c++ cheatsheet

GermanSilo
Junior Member
Prime
Level:
8
Reputation:
0
Posts:
69
Likes:
21
Credits:
38
20-11-2023, 01:15 PM
#2
Thank you! Won't need it, but it's always nice to see people care about c++ beginners.

RE: c++ cheatsheet

blessgen
Lurker
Level:
0
Reputation:
0
Posts:
4
Likes:
1
Credits:
0
31-03-2024, 03:58 PM
#3
fddf gdg dg dsg dg sdgd dsgdsg sfs dfs sdf
1

RE: c++ cheatsheet

charyy
Newbie
Level:
1
Reputation:
0
Posts:
15
Likes:
0
Credits:
3
26-04-2024, 09:43 PM
#4
Thank you! Won't need it, but it's always nice to see people care about c+

Users browsing this thread: 1 Guest(s)