Your First Program and Output
Write your first C++ program and print text to the screen.
A program is a sequence of instructions that a computer executes. In C++ the instructions go into a source-code file, and a compiler turns it into an executable.
Let's start with the most famous program in the world — it prints a greeting to the screen. Press "Run" below the code and look at the result.
C++
Your first C++ program — try running it
Let's go through the program line by line:
• #include <iostream> — includes the input/output library: without it std::cout will not work.
• int main() { ... } — the main function: execution of every C++ program starts here.
• std::cout << "Hello, World!" — prints text to the screen.
• std::endl — moves to a new line.
• return 0 — tells the system the program finished successfully.
Try changing the text inside the quotes right in the block above and run the program again.
C++
std::cout can print both text and the results of calculations
Practice task: print three lines — your name, your city, and the result of 7 * 6. Each value on its own line.
Once it works, mark the lesson as completed and move on to the next one: "Variables and Data Types".