C++ is a powerful and versatile programming language that extends the C programming language with additional features such as object-oriented programming. Here's an example of a "Hello, World!" program in C++:
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Explanation:
- The `#include <iostream>` directive includes the input/output stream library (`iostream`) in the program. This library provides input/output operations like `cout` and `endl`.
- The `int main()` function is the entry point of the program. It is where the execution of the program starts.
- The `std::cout` object is used to display output. `cout` is part of the `iostream` library and is used with the insertion operator `<<`. In this case, it outputs the string "Hello, World!".
- The `std::endl` manipulator is used to insert a newline character and flush the output buffer. It is used to end the line after printing "Hello, World!".
- The `return 0;` statement indicates the end of the `main()` function. By convention, returning 0 signifies successful execution of the program.
When you compile and run this C++ program, it will print "Hello, World!" on the console. This program showcases the basic functionality of the `cout` object to display output in C++.
0 Comments