Ch 2 · Your First C++ Program · C++

Topic 2 of 13 in C++ — Complete Tutorial (Beginner) — 2 lessons.

Hello World!

Every C++ program starts in main. To print, we use cout (pronounced "see-out"), which comes from the <iostream> library we include at the top. You send text to cout with the << operator, and endl (or "\n") ends the line. The line using namespace std; lets us write cout instead of std::cout — a convenience for beginners.

cout and Chaining

The real elegance of cout is chaining: you can stream many values in a row with multiple << operators, mixing text, numbers, and variables freely. Each << passes the next item to the output. Unlike C's printf, you do not need format specifiers — cout figures out each value's type automatically.

All topics in C++ Beginner

  1. Introduction to Programming & C++
  2. Your First C++ Program
  3. Variables & Data Types
  4. Input & Output
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Vectors & Strings
  10. Classes & Objects
  11. Working with Classes
  12. Exception Handling
  13. Mini-Projects & Practice