Installing and Setting Up C++
To write and run C++ programs, we need two main things:
- A C++ Compiler: It converts C++ code into machine code (e.g., GCC, MSVC).
- An Editor or IDE: A place to write your code (e.g., VS Code, Code::Blocks, Dev-C++, etc.).
1. Setup C++ in VS Code (Windows):
- Download and install VS Code from https://code.visualstudio.com/.
- Install the MinGW (G++) compiler:
- Download from: MinGW-w64.
- During setup, select architecture as
x86_64
and threads asposix
. - Add the
bin
folder path to System Environment Variables > Path.
- In VS Code, install the C/C++ extension by Microsoft.
- Open your C++ file and save it with
.cpp
extension. - Use the terminal to compile:
g++ filename.cpp -o output
- Then run the program:
./output
2. For Linux Users:
- Open terminal and type the following command:
sudo apt update
sudo apt install g++
Now you can write and run C++ programs directly from the terminal.
3. For macOS Users:
- Install Xcode Command Line Tools by running:
xcode-select --install
This installs the Clang compiler which supports C++. You can also use IDEs like VS Code or Xcode.
4. Verifying Installation
To verify that the C++ compiler is installed correctly, open terminal or command prompt and type:
g++ --version
If you see version information, it means your compiler is ready to use.
Summary:
- Install a C++ compiler like GCC (via MinGW or built-in on Linux/macOS).
- Use a text editor or IDE (like VS Code, Code::Blocks).
- Set environment paths (on Windows).
- Use terminal/command prompt to compile and run C++ code.