C++ Install & Setup
To compile C++ you need a compiler such as GCC (g++), Clang, or MSVC on Windows. Many Linux distros ship g++ already; on Mac you can install Xcode command line tools, and on Windows you can use MinGW or Visual Studio.
Once installed, you compile a `.cpp` file into an executable and then run that executable separately โ unlike interpreted languages, there's a distinct build step.
g++ file.cpp -o file && ./fileVerify the install
Run `g++ --version` in a terminal. If it prints a version number, you're ready to compile C++ code.
Editors and IDEs
VS Code with the C/C++ extension, CLion, and Code::Blocks are popular. Competitive programmers often use a single main.cpp with a terminal build command.
g++ --versiong++ (GCC) 13.2.0Shows the installed GCC/g++ version.
g++ hello.cpp -o hello
./helloHello, World!Compiles hello.cpp into an executable named hello, then runs it.
Key points
- Install g++ (GCC), Clang, or MSVC.
- Compiling and running are two separate steps.
- Use `g++ file.cpp -o out` to build an executable.
- VS Code + C/C++ extension is a common free setup.
