Lesson 1: Your First C++ Program
Welcome to C++! You already know C, so the structure will feel familiar: there's a main, and a return 0. The first small difference: instead of printf, in C++ you print with std::cout. In this lesson we'll learn just one thing — how to print a line to the screen. That's it. Nothing else. We compile
std::cout is printf's friendly cousin: you write std::cout, then << ('send this to the screen'), then whatever you want to print.
- std::cout
- The object that prints to the screen in C++. You print to it with <<, e.g. std::cout << "Hi";
- << (insertion operator)
- Sends a value to std::cout to be printed. std::cout << "Hi"; sends Hi to the screen.
- <iostream>
- The C++ header that contains std::cout. You include it with #include <iostream> (like stdio.h in C).
- \n
- The 'newline' character. At the end of a string it moves to a new line in the output — exactly like in C.