Game Leaks

c++ cheatsheet

Submitted by 2UG21CS134, , Thread ID: 278917

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

#2
Thank you! Won't need it, but it's always nice to see people care about c++ beginners.

RE: c++ cheatsheet

#3
Thank you! Won't need it, but it's always nice to see people care about c+

RE: c++ cheatsheet

#4
I'm grateful. Not that I'll need it, but it's always good to know that C++ novices are taken care of.

RE: c++ cheatsheet

#5
09-11-2023, 11:15 AM
2UG21CS134 Wrote:
// 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;
}

lol thanks bro this ihuge

RE: c++ cheatsheet

#6
thank you for the help im looking forward to learn a bit more about c++

RE: c++ cheatsheet

#7
lol thanks bro this ihuge
RE: c++ cheatsheet
nky17
nky17
Newbie
Level:
1
Reputation:
0
Posts:
12
Likes:
0
Credits:
0
7 hours ago
#6
thank you for the help im lo

RE: c++ cheatsheet

#8
de 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

RE: c++ cheatsheet

#9
thank you so much appreciate that

RE: c++ cheatsheet

#10
wow this was really helpfull! impressed!

Users browsing this thread: 1 Guest(s)