Creating your first C++ program is a great way to start learning the language! The most classic first program is the "Hello, World!" example. Here's how you can write and run a basic C++ program:
#include <iostream> <!-- Include the standard input-output stream library -->
int main() { <!-- Entry point of the program -->
std::cout << "Hello, way to code" << std::endl; <!-- Print to
the console -->
return 0; <!-- Exit the program -->
}
Hello, way to code
• #include <iostream>: This line includes the input-output stream library which is necessary for using std::cout to print text to the console.
• int main(): This is the main function where the execution of the program starts. It returns an integer value to the operating system when the program finishes.
• std::cout << "Hello, World!" << std::endl;: This line outputs the text "Hello, World!" followed by a newline to the console. std::cout is the standard character output stream.
• return 0;: This statement returns 0 to the operating system, indicating that the program has finished successfully.