capypad
0 day streak
cpp / beginner
Snippet

The Basic Structure of a C++ Program

Every C++ program starts with a main function. We use #include <iostream> to allow us to print text to the console.

snippet.cpp
cpp
1
2
3
4
5
6
#include <iostream>
 
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Breakdown
1
#include <iostream>
Includes the standard library for input and output operations.
2
int main() { ... }
The entry point where the execution of the program begins.
3
std::cout << "Hello, World!";
Prints the text string to the standard output (console).