Hello, C++
C++ is a compiled, statically-typed language, your source code is translated into machine code by a compiler before the program ever runs. That extra step is part of why C++ programs run so fast, and why "compile errors" catch many mistakes before you even try running anything. It's used everywhere performance matters: games and game engines, operating systems, embedded devices, and other high-performance software.
Your first program
#include <iostream>
int main() {
std::cout << "Hello, Kodstigen!" << std::endl;
return 0;
}
Reading it line by line
#include <iostream>pulls in the input/output library, without itstd::coutwouldn't exist.int main() { ... }is the entry point, every C++ program starts running here, and only here.std::cout << "..."sends text to the console,std::means "this comes from the standard library", and<<pushes a value into the output stream.std::endlends the current line.return 0;tells the operating system the program finished successfully, by convention0means "no errors" (anything else signals a problem).
Compiling and running
Unlike Python or JavaScript, C++ code doesn't run directly, a compiler translates it into an executable first:
g++ hello.cpp -o hello
./hello
g++ hello.cpp -o hello compiles hello.cpp into a program named hello, ./hello then runs it.