Contact
Evil Genius SocietyHomeLearnForumLeaderboardSocialsMessages
← Back to module

Lesson 6 of 6

Everything from this module comes together here. You're going to create a file, write a small program, compile it, and run it — the exact loop you'll repeat for the rest of this course.

Create the file

In your VS Code terminal, make sure you're in your course folder, then create a new file called hello.cpp:

cd ~/cpp-course

Now, in the VS Code file explorer (or by running code hello.cpp in the terminal), create hello.cpp and type this into it exactly:

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Type it rather than copy-pasting, if you can — getting used to the exact punctuation (the semicolons, the braces, the <<) is part of what this lesson is for. Save the file (Ctrl+S / Cmd+S).

Compile it

Back in the terminal, still inside ~/cpp-course, run:

g++ hello.cpp -o hello

Read that as: "compile hello.cpp, and name the output hello." If everything's set up correctly, this command finishes silently — no output at all means it worked. A compiler that has nothing to complain about says nothing.

If you see red text instead, don't panic — read it, don't just close it. It'll usually point at a specific line and describe what's wrong (a missing semicolon is the classic first mistake). Fix what it describes, save, and run the g++ command again.

Run it

The compiler produced a new file. Run it:

./hello

You should see:

Hello, World!

printed to your terminal. That's a real, compiled, standalone program — you could copy that hello file to another computer with no compiler installed at all, and it would still run.

What you just did, briefly

You don't need to fully understand every part of this yet — that's the whole next module — but here's the shape of it:

  • #include <iostream> pulls in the tools needed for terminal input/output.
  • int main() { ... } is the function every C++ program starts running from.
  • std::cout << "..." prints text.
  • return 0; tells the operating system the program finished successfully.

Check yourself

If something didn't work

  • g++: command not found — go back to your OS-specific setup lesson; the compiler install didn't finish.
  • ./hello: No such file or directory — the g++ command above it must have failed. Scroll up in your terminal and read the actual error.
  • code/VS Code terminal doesn't have g++ — on Windows, make sure you opened your project with code . from inside your WSL Ubuntu terminal, not from a plain Windows terminal.

Module 1 complete

You now have a real, working C++ development environment — a compiler, a debugger, and an editor set up to use both — and you've proven it works by writing, compiling, and running an actual program. Every lesson from here on assumes exactly this setup.

Next up: Module 2, where the real language begins.

Questions about this lesson

Log in to ask a question.