Hello, C++!
main.cpp
123456#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
The example above is a classic starting point for every C++ programmer. Each line in this simple program has a specific role:
- The first line,
#include <iostream>, tells the compiler to include the input/output stream library. This library gives you access to objects likestd::cout, which is used for printing text to the screen; - The next part,
int main() { ... }, defines the main function. Every C++ program must have amainfunction, as this is where the program begins running; - Inside the main function, the line
std::cout << "Hello, World!" << std::endl;sends the text"Hello, World!"to the output stream, which displays it on your screen. The<<operator is used to pass the string tostd::cout, andstd::endladds a new line after the text; - The final line,
return 0;, ends the main function and returns the value0to the operating system. This is a way of signaling that the program finished successfully.
Even though this program is short, it introduces you to the basic building blocks of every C++ application: including libraries, defining the main function, displaying output, and signaling successful completion.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 6.67
Hello, C++!
Swipe to show menu
main.cpp
123456#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
The example above is a classic starting point for every C++ programmer. Each line in this simple program has a specific role:
- The first line,
#include <iostream>, tells the compiler to include the input/output stream library. This library gives you access to objects likestd::cout, which is used for printing text to the screen; - The next part,
int main() { ... }, defines the main function. Every C++ program must have amainfunction, as this is where the program begins running; - Inside the main function, the line
std::cout << "Hello, World!" << std::endl;sends the text"Hello, World!"to the output stream, which displays it on your screen. The<<operator is used to pass the string tostd::cout, andstd::endladds a new line after the text; - The final line,
return 0;, ends the main function and returns the value0to the operating system. This is a way of signaling that the program finished successfully.
Even though this program is short, it introduces you to the basic building blocks of every C++ application: including libraries, defining the main function, displaying output, and signaling successful completion.
Thanks for your feedback!