C/C++ Arena

Step 1 of 7

Hello, C++

Welcome to C++. Bjarne Stroustrup started it in 1979 as "C with Classes" and renamed it C++ in 1983, and almost everything you learned in C still works: variables, if, loops, functions, pointers, arrays and structs. What C++ adds are tools that make programs safer and shorter: classes that clean up after themselves, a huge standard library (strings, dynamic arrays, maps, algorithms), references, templates and more.

The first difference you'll notice is output. Instead of printf with format specifiers, C++ uses streams:

#include <iostream>

int main() {
    int kills = 25;
    double accuracy = 0.61;
    std::cout << "Kills: " << kills << "\n";
    std::cout << "Accuracy: " << accuracy << " (" << accuracy * 100 << "%)\n";
}
Kills: 25
Accuracy: 0.61 (61%)

How it works

You'll see std::endl in older code; it prints a newline and flushes the stream, which is slower. "\n" is usually what you want.

Your turn: print Rounds won: 13 using cout.

Next: Reading with cin