Game Leaks

c++ cheatsheet

Submitted by 2UG21CS134, , Thread ID: 278917

RE: c++ cheatsheet

shacootpyaso
Newbie
Level:
1
Reputation:
0
Posts:
16
Likes:
0
Credits:
0
30-05-2024, 05:22 PM
#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

Users browsing this thread: 1 Guest(s)