Hello, World!
To compile and build a C++ program, follow these steps:
Install a C++ Compiler: Ensure you have a C++ compiler installed, such as
g++
(part of GCC) orclang++
.Write Your C++ Code: Create a file named
main.cpp
with your C++ code. For example:#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }Open Terminal: Navigate to the directory containing your
main.cpp
file.Compile the C++ Code: Use the
g++
orclang++
command to compile your C++ code into an executable.g++ main.cpp -o mainRun the Executable: After compilation, run the generated executable.
./main
These steps will compile and build your C++ program, allowing you to run the resulting executable.
Last modified: 20 November 2024