Skip to content

Cpp

cotrPrint

C++ Print

#include <iostream>
std::cout << ${1:"Your message here"} << std::endl;

cotrIf

C++ If Statement

if (${1:condition}) {
// Your code here
}

cotrTypesDynamic

C++ Dynamic Type

std::any

cotrVarNum

C++ Create Double Variable

double ${1:myDouble} = ${2:value};

cotrVarList

C++ Create List Variable

std::vector<${1:type}> ${2:myList} = {${3:values}};

cotrTypesNumAlt

C++ Float Type

float

cotrVarMap

C++ Create Map Variable

std::map<${1:keyType}, ${2:valueType}> ${3:myMap} = {
{${4:key1}, ${5:value1}},
{${6:key2}, ${7:value2}},
// Add more key-value pairs here
};

cotrIfElse

C++ If Else Statement

if (${1:condition}) {
// Your code here
} else if (${2:condition}) {
// Your code here
} else {
// Your code here
}

cotrVarDate

C++ Create Date Variable

#include <chrono>
auto ${1:myDate} = std::chrono::system_clock::now();

cotrTypesDate

C++ Date Type

#include <chrono>
std::chrono::system_clock::time_point

cotrVarNullable

C++ Create Nullable Variable

std::optional<${1:Type}> ${2:myVar} = $3;

cotrVarInt

C++ Create Integer Variable

int ${1:myInt} = ${2:value};

cotrTypeCheck

C++ Type Check

typeid(${1:variable})

cotrDoWhileLoop

C++ Do…While Loop

do {
// Your code here
} while (${1:condition});

cotrTypesNull

C++ Null Type

nullptr

cotrForLoop

C++ For Loop

for (int ${1:i} = 0; $1 < ${2:10}; $1++) {
// Your code here
}

cotrWhileLoop

C++ While Loop

while (${1:condition}) {
// Your code here
}

cotrFuncLambda

C++ Lambda and Anonymous Function

auto ${1:myLambda} = [](${2:parameters}) -> ${3:returnType} {
// Your code here
};
// Or without assigning to a variable:
[](${2:parameters}) -> ${3:returnType} {
${3:// Your code here}
}

cotrTryCatch

C++ Try Catch

try {
// Your code here
} catch (${1:exceptionType} ${2:exception}) {
// Your code here
}

cotrNotEqual

C++ Not Equal To

!=

cotrTypes

C++ Types

$BLOCK_COMMENT_START
C++ is a statically typed language.
Types in C++ include:
- int: Integer
- float: Single-precision floating-point number
- double: Double-precision floating-point number
- char: Character
- bool: Boolean
- std::string: String class from the Standard Library
- int[10]: Array of integers with size 10
- std::vector<int>: Vector of integers from the Standard Library
- std::map<K, V>: Map (associative array) from the Standard Library
- struct MyStruct: Custom data structure with named fields
- enum MyEnum: Enumeration type
- void: Type representing the absence of a value
- auto: Type inferred by the compiler
- nullptr: Type of the null pointer
- decltype: Type specifier for the type of an expression
Read more here: https://learn.microsoft.com/en-us/cpp/cpp/fundamental-types-cpp?view=msvc-170
$BLOCK_COMMENT_END

cotrTypesChar

C++ Character Type

char

cotrVarNumAlt

C++ Create Float Variable

float ${1:myFloat} = ${2:value};

cotrFunc

C++ Function

void ${2:myFunction}(${3:parameters}) {
${4:// Your code here}
}

cotrFuncArgsNamed

C++ Function Named Args

// C++ does not support named arguments in the same way as some other languages.

cotrTypesNum

C++ Double Type

double

cotrNow

C++ Date Now

std::chrono::system_clock::now()

cotrVar

C++ Create Variable

${1:type} ${2:myVar} = ${3:value};

cotrVarSyntax

C++ Variable Declaration Syntax

// C++ Variable Declaration Syntax:
// - auto: (Scope: Block)
// - Type is automatically inferred by the compiler.
// - Preferred for most variable declarations.
// - type: (Scope: Block)
// - Explicitly specify the variable's type.
// - Use when auto deduction is not desired or not possible.
// - const: (Scope: Block)
// - Cannot be reassigned or redeclared.
// - Use for values that should remain constant.
// Note:
// - C++ does not have a direct equivalent to 'var' or 'let'.
// - Use 'auto' for most variable declarations.
// - Use 'const' for values that should not change.

cotrVarTyped

C++ Create Typed Variable

${1:Type} ${2:myVar} = $3;

cotrOperators

C++ Mathematical Operators

// C++ Mathematical Operators
// Addition: +
// Subtraction: -
// Multiplication: *
// Exponentiation: **
// Division: /
// Modulus: %
// Increment: ++
// Decrement: --
// Assignment: =
// Addition assignment: +=
// Subtraction assignment: -=
// Multiplication assignment: *=
// Division assignment: /=
// Modulus assignment: %=

cotrTypesInt

C++ Integer Type

int

cotrThrow

C++ Throw Exception

throw ${1:Exception('Your message here')};

cotrClass

C++ Class

class ${1:MyClass} {
// Your code here
};

cotrTypesBoolTrue

C++ Boolean True

true

cotrTypesBoolFalse

C++ Boolean False

false

cotrVarStatic

C++ Static Variable

static ${2:type} ${3:myStaticVar} = ${4:value};
// Access the static variable
// MyClass::${3:myStaticVar}

cotrVarBool

C++ Create Boolean Variable

bool ${1:myBool} = ${2:value};

cotrForInLoop

C++ For…In Loop

for (auto ${1:item} : ${2:iterable}) {
// Your code here
}

cotrFuncArgs

C++ Function Args

// In C++, you can use default arguments in function definitions.
void ${2:myFunction}(${3:Type} ${4:arg1}, ${5:Type} ${6:arg2} = ${7:defaultValue}) {
${8:// Your code here}
}

cotrComment

C++ Comment

// ${1:Your comment here}

cotrInfo

C++ Info

// Typing: Statically typed
// Paradigm: Multi-paradigm: procedural, object-oriented, functional, generic, imperative
// Compilation: Compiled
// Concurrency: Supports multi-threading

cotrStructure

C++ Project Structure (High-Level)

// Recommended High-Level C++ Project Structure:
// - src/
// For Feature or Module-based Organization:
// - rendering/
// - Contains source code for rendering features.
// - physics/
// - Contains source code for physics features.
// - networking/
// - Contains source code for networking features.
// For File Type-based Organization:
// - cpp/
// - Contains all .cpp implementation files.
// - h/
// - Contains all .h header files.
// - Contains all source code.
// - include/
// - Contains header files.
// - build/
// - Output directory for compiled files.
// - lib/
// - Contains external libraries (if not using a package manager).
// - test/
// - Contains unit tests.
// Note:
// - This is a basic structure; adjust based on project complexity and preferences.

cotrTypeCompare

C++ Type Comparison

// Check if two variables have the same type:
if (typeid(${1:variable1}) == typeid(${2:variable2})) {
// Your code here
}

cotrInterpolate

C++ Interpolate String

std::string ${1:myString} = "${2:Your message here}";

cotrConcat

C++ Concatenate Strings

std::string ${1:myString} = ${2:"Hello, "} + ${3:"world!"};

cotrVarStringMulti

C++ Create Multi-Line String Variable

std::string ${1:myString} = R"(${2:Your multi-line message here})";

cotrConst

C++ Create Constant

const ${1:type} ${2:myConst} = ${3:value};

cotrFuncSyntax

C++ Function Syntax

// C++ Function Syntax
// Basic function: returnType functionName(parameters) { ... }
// Function with arguments: returnType functionName(arg1Type arg1, arg2Type arg2, ...) { ... }
// C++ does not support named arguments in the same way as some other languages.

cotrOperatorsBool

C++ Boolean Operators

// C++ Boolean Operators
// Logical AND: &&
// Logical OR: ||
// Logical NOT: !
// Equality: ==
// Inequality: !=
// Greater than: >
// Less than: <
// Greater than or equal to: >=
// Less than or equal to: <=

cotrTypeConvert

C++ Type Conversion

// C++ Type Conversion:
// Implicit conversions (compiler performs automatically):
// - Smaller integer types to larger integer types (e.g., int to long).
// - Integers to floating-point types (e.g., int to double).
// Explicit conversions (using casts):
// - static_cast<Type>(expression): For safe conversions within compatible types.
// - dynamic_cast<Type>(expression): For safe conversions between polymorphic types.
// - const_cast<Type>(expression): For removing constness.
// - reinterpret_cast<Type>(expression): For low-level reinterpretations of data.
// Example:
// int x = 5;
// double y = static_cast<double>(x);

cotrTypesMap

C++ Map Type

std::map<${1:keyType}, ${2:valueType}>

cotrTypesList

C++ List Type

std::vector<${1:type}>

cotrSwitch

C++ Switch Statement

switch (${1:variable}) {
case ${2:value1}:
// Your code here
break;
case ${3:value2}:
// Your code here
break;
default:
// Your code here
}

cotrTernary

C++ Ternary Operator

${1:condition} ? ${2:trueValue} : ${3:falseValue}

cotrGenList

C++ Generate List

std::vector<${1:type}> ${2:listName}( ${3:size}, ${4:initialValue} );

cotrPrintMulti

C++ Print Multi

#include <iostream>
std::cout << ${1:"Line 1"} << std::endl
<< ${2:"Line 2"} << std::endl
<< ${3:"Line 3"} << std::endl;

cotrCommentMulti

C++ Multi-Line Comment

/*
* ${1:Your comment here}
*/

cotrEntry

C++ Entry Point

// C++ Entry Point
// To compile and run this program, use: `g++ filename.cpp -o output && ./output`
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}

cotrTypesString

C++ String Type

std::string

cotrEnum

C++ Enum

enum class ${1:MyEnum} {
${2:value1},
${3:value2},
// Add more values here
};

cotrTypesBool

C++ Boolean Type

bool

cotrGenMap

C++ Generate Map

// C++ does not have a built-in way to generate a map with a specific number of key-value pairs.
// You can use a loop or a custom function to achieve this.

cotrEqual

C++ Equal To

==

cotrVarString

C++ Create String Variable

std::string ${1:myString} = ${2:value};