C++
Type core C++ syntax, standard library containers, functions, and classes.
Variables and Output
FácilDeclare values and print a formatted message.
#include <iostream>
#include <string>
int main() {
std::string name = "Mira";
int score = 128;
std::cout << name << ": " << score << " points\n";
return 0;
}Loop Over a Vector
MedioUse a range-based loop to total vector values.
#include <iostream>
#include <vector>
int main() {
std::vector<int> values{4, 8, 15, 16, 23, 42};
int total = 0;
for (int value : values) {
total += value;
}
std::cout << total << '\n';
}Function Overloading
MedioDefine overloads for integer and decimal values.
#include <iostream>
int doubleValue(int value) {
return value * 2;
}
double doubleValue(double value) {
return value * 2.0;
}
int main() {
std::cout << doubleValue(12) << '\n';
std::cout << doubleValue(2.5) << '\n';
}