Hello World in C++/ CPP
Here's an example of a "Hello, World!" program in C++:c++Copy code
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
The #include <iostream> statement is used to include the standard input-output stream library in the program. The main() function is the starting point of the program, and it is where the execution of the program begins. The std::cout statement is used to print the "Hello, World!" message to the console, and the << operator is used to insert the message into the output stream. The std::endl statement is used to insert a new line after the message is printed. Finally, the return 0; statement is used to exit the program.
When you compile and run this program, you should see the "Hello, World!" message printed to the console.
Note that in C++, the std:: prefix is used before the cout and endl statements because these are part of the std namespace. Also, it is required to have a main function and the function should return an integer value, which is why we have return 0; statement at the end.
Comments
Post a Comment