The code
This is a whole C++ program in one file, greet.cpp. It asks for your name, waits for you to type it, then greets you. It runs from top to bottom, one line at a time.
Lines 1 and 2 bring in ready-made tools from the standard library. <iostream> gives std::cout (the screen) and std::cin (the keyboard). <string> gives std::string, a piece of text. std:: means 'from the standard library'.
Running it line by line
In the terminal, type g++ greet.cpp -o greet to turn the text into a program called greet. No message means it worked. Then type ./greet to run it. Running starts at main, on line 3.
Line 4 makes a variable: a named box in memory. Its type, std::string, says the box holds text. It starts empty, holding "", the text with nothing in it.
Line 5 sends the text Name? to the screen. The arrows << point the way the text goes: into std::cout. There is no new line, so your answer will appear right after the question.
Line 6 waits. You type Ada and press Enter. std::cin >> name reads that word from the keyboard and puts it in the box. The arrows >> point into name. The box now holds "Ada".
Line 7 chains two pieces with <<: the fixed text "Hi, " and then the value in name. Reading name copies it; the box still holds "Ada". Line 8 adds ! and a new line (\n). The screen shows Hi, Ada!
Line 9 ends main. The program stops and hands the number 0 to the system, which means success. Type echo $? to see it. The box is gone too: a program's memory is freed when it ends.
A surprise
Run it again and type Ada Lovelace. The greeting still says Hi, Ada! because >> stops reading at the first space. "Lovelace" is left waiting, unread. To read a whole line, use std::getline(std::cin, name).
What happens
;; step 1/9 · program
greet.cpp
1 #include <iostream>
2 #include <string>
3 int main() {
4 std::string name;
5 std::cout << "Name? ";
6 std::cin >> name;
7 std::cout << "Hi, " << name;
8 std::cout << "!\n";
9 return 0;
10 }
a statement is one instruction; most end with ;
g++ greet.cpp -o greet builds the program in one command (the preprocessor, compiler and linker run in turn). Adding -std=c++20 -Wall -Wextra picks the C++20 rules and turns on helpful warnings; this program builds with no warnings either way. With Clang, type clang++ instead of g++. std::cin >> name first skips any spaces, tabs or new lines, then reads characters up to the next one. The rest stays in the input, where the next read would find it. std::getline reads up to the end of the line instead.