📅  最后修改于: 2023-12-03 15:29:49.762000             🧑  作者: Mango
In this tutorial, we will learn how to print "Hello, World!" in C++. "Hello, World!" is often the first program that beginners write when learning a new programming language. It is a good starting point for understanding basic syntax and structure in a language.
Before we start, you should have a basic understanding of C++ programming concepts such as data types, variables, and functions.
Open a new C++ source file.
In the source file, include the iostream
header file.
#include <iostream>
Now, we are ready to print "Hello, World!" to the console. Add the following code inside the main()
function:
std::cout << "Hello, World!";
This code uses the std::cout
object to output the string "Hello, World!" to the console. The <<
operator is used to stream the string to the std::cout
object.
Save the source file with a .cpp
extension.
Compile the source file into an executable file. Depending on your development environment, you can compile the source code using a command-line interface or an integrated development environment (IDE).
Run the executable file to see the output. You should see "Hello, World!" printed to the console.
#include <iostream>
int main() {
std::cout << "Hello, World!";
return 0;
}
Congratulations! You have successfully written a "Hello, World!" program in C++. This program is a simple example of how to use the std::cout
object to output text to the console. As you continue learning C++, you will build on this foundation and learn more advanced concepts.