Hello World!
Part of the Fundamentals section of Coddy's C++ journey — lesson 2 of 74.
The "Hello World!" is a simple program that outputs Hello World! to the screen.
In C++, we use std::cout to print output to the console. The text to be printed is placed within double quotes and followed by the insertion operator <<.
Before we can use std::cout, we need to include the iostream library at the top of our file. This is done with #include <iostream>. The iostream library provides the tools needed for input and output — without it, std::cout would not be available.
Let's take a look at the "Hello World!" program in C++:
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}Challenge
BeginnerUse the code view to write a program that outputs Hello World!
Note that anything inside quotation marks is case sensitive. For example:
std::cout << "Hello World!";std::cout << "hello world!";are different things (notice the capital letters in the first line).
Write your code inside the curly braces of main(), before the return 0; line.
Cheat sheet
To print to the console in C++, use std::cout with the insertion operator <<:
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}Try it yourself
#include <iostream>
int main() {
// Your code goes here, before return 0
return 0;
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison3Variables Part 2
Type DeclarationNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementConditional OperatorRecap - If ElseNested If - Else