📅  最后修改于: 2023-12-03 15:31:07.148000             🧑  作者: Mango
C++ is a programming language that was developed in the late 1970s by Bjarne Stroustrup. It is an extension of the C programming language, and provides object-oriented features to the language.
"Hello World" is a simple program that is commonly used as an introduction to programming. It is an easy program to write, and serves as a way for programmers to get familiar with the syntax of the language they are working with.
To write a "Hello World" program in C++, you will need a text editor and a C++ compiler. Here is an example of a "Hello World" program in C++:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
#include <iostream>
is a preprocessor directive that tells the compiler to include the standard input-output library in the program.using namespace std
tells the compiler to use the standard namespace for input and output operations.int main()
is the entry-point function of every C++ program. It returns an integer value (in this case 0) to the operating system to indicate if the program ran successfully or not.cout
is an output stream object that allows us to print output to the console."Hello World!"
is the message we want to print to the console.<< endl
is an endline character that tells the console to move to a new line.To compile and run the program on your computer:
helloworld.cpp
.cd
command.g++ helloworld.cpp -o helloworld
to compile the program. This will generate an executable file called helloworld
../helloworld
to run the program.You should see the message "Hello World!" printed to the console.
Congratulations! You have written and executed your first C++ program. This is just the beginning of your journey learning C++. There are many more concepts and features of the language to explore.