Skip to content
Hello, World
step 1/5

Reading — step 1 of 5

Learn

~2 min readGetting Started

Hello, World

C++ is C's ambitious descendant: it kept the "you control everything" engine and bolted on forty years of abstraction — classes, templates, a real standard library. The result is the language of game engines, browsers, and trading systems: huge, powerful, and learnable in layers. This course is the first layer, and it starts where every C++ program starts:

#include <iostream>

int main() {
    std::cout << "Hello, World" << std::endl;
    return 0;
}
  • #include <iostream> — pulls in the standard I/O stream library. C++ inherits C's headers-and-preprocessor model: ask for what you use.
  • int main() — same contract as C: the entry point, returning 0 to the OS for success (and C++ returns 0 implicitly from main if you don't).
  • std::cout << … — the star of the show. cout is the standard output stream; << inserts values into it. Chaining beats format strings for type safety: the compiler picks the right output routine for each value's type — no %d-vs-%s mismatches, ever.
  • std::endl — newline plus a flush. "\n" is the lighter alternative (newline only) and what performance-minded code uses; for this course either passes, but know they differ.

About std::

std:: is a namespace — the standard library's family name, preventing its count from colliding with your count. Writing std:: everywhere is the professional default, and this course's lessons do. You'll also see using namespace std; in tutorials and competitive code — it dumps the entire namespace into scope. Fine in a 20-line exercise, banned in most real codebases (header pollution); prefer the explicit form and you'll never have to unlearn anything.

Input is symmetric

int age;
std::string name;
std::cin >> name >> age;      /* >> extracts, skipping whitespace */
std::cout << "Hi " << name << ", " << age << "\n";

cin >> x reads a whitespace-separated token into xany whitespace, spaces or newlines, which means grader input parses identically however it's laid out. And notice what's missing versus C: no &, no format specifier. The stream knows age is an int because C++ overloads >> per type. (When input is dirty or line-oriented you'll meet std::getline; for this course's clean token streams, >> is exactly right.)

Compile and run

$ g++ -Wall -o hello hello.cpp
$ ./hello

Same toolchain family as C, same advice: -Wall always. C++ error messages have a reputation — one bad template call can produce a page of complaint — so learn the survival skill now: read the first error only, fix it, recompile. The rest are usually echoes.

Your exercise

Print the exact text. std::cout, one << chain, newline included, byte-exact. Then — tradition — break it: drop a semicolon, misspell cout, and read what g++ says. Meeting the error format on a three-line program is the cheapest tuition you'll ever pay.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…

Hello, World — C++ Fundamentals