Ultimate Guide: C++ Setup in Visual Studio Code (VS Code)
if you Want to write and run C++ code in Visual Studio Code, but not sure how to setup vs code for c++? in this blog article i tell you how to install c++ in vscode
Step-by-Step process for How to Set Up C++ in VS Code
Step 1: First we have to Download & Install Visual Studio Code
For Install VS code You have to Go to: [(https://code.visualstudio.com)
Download for your OS according to your device (Windows, Mac, Linux)
Install like a normal app
Step 2:Now we have to Install a C++ Compiler
C++ needs a compiler to run our code.
For Windows Use MinGW-w64 (a popular C++ compiler for Windows)
you can Download from:
https://www.mingw-w64.org/](https://www.mingw-w64.org/
Steps:
1. Run the installer and choose the architecture for 32 bit or 64 bit according to your device
2. Install it in a folder
3. now you have to go in this folder then bin and copy the path
Step 3: We have to Add Compiler to System PATH (Windows)
How to Add MinGW to PATH f (Windows):
1. First Open the Start menu, search for → `Environment Variables`
2. Click on "Edit the system environment variables"**
3. In the window, click the button → "Environment Variables"
4. Under System variables, find → `Path` → Click Edit
5. Click New and paste in the path to your `bin` folder.
For example:
C:\Program Files\mingw-w64\...\bin
6. Click OK, OK, OK.
And Our Setup of VS code is almost done
Now open a new terminal and type:
g++ --version
You should see the version info, it means it works!
vs code setup for c++ in macOs:
Just open Terminal and run this command for Confirms it installation XCode-select --install
This installs Apple’s official C++ tools, including `clang`
- Setup For Linux (Ubuntu) for Vs code
For Ubuntu user You have to go In Terminal type this command
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential gdb
This Will install tools like `g++`, `gcc`, `make`, and other tools.
Step 4:Now We have to Install C++ Extension in VS Code
1.First Open VS Code
2. Go to the left sidebar → Click Extensions (or press shortcut for `Ctrl+Shift+X`)
3. Search: `C/C++`
4. Install the one by Microsoft
This gives us features like IntelliSense, debugging, and more.
Step 5:now how we can create our first c++ program
1. First We have to Make a new folder (e.g., `my-cpp-project`)
2. in that folder create a file: `first.cpp`
Write this code
cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello, C++ in VS Code!" << endl;
return 0;
}
Step 6: Set Up Build Task to Compile Your Code
Let’s make it easy to compile your code with one shortcut.
1. In VS Code, go to the top menu:
Terminal → Configure Default Build Task
2.You have to go and choose: C/C++: g++ build active file
It will help us for auto-create a `.vscode` folder with a `tasks.json` file.
Now press `Ctrl + Shift + B` → This help us for builds (compiles) our code!
Step 7: For Run our Program
After compiling, a new file will be created:
1.On Windows → `main.exe`
2.On Linux/macOS → `a.out`
for run it:
Open Terminal in VS Code, then type:
./main.exe ← for
Windows
./a.out ← for Linux/macOS
You’ll see output:
Hello, C++ in VS Code
Frequently asked questions:
1.how to check mingw installed or not in cmd.
Ans:To Check Mingw installed or not in cmd open a new terminal and type:g++ --version
If You see the version info, it means it works!
2.how to setup vs code for c++ in ubuntu
Ans:For Ubuntu user You have to go In Terminal type this command
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential gdb
This Will install tools like `g++`, `gcc`, `make`, and other tools.
Conclusion: Here in this blog Article I have share how to setup or install Visual studio for Windows Macbook and Ubuntu for C++ and How to write Your first C++ program in Visual studio And also Some Shortcut also to Run Code on Visual Studio I hope You Like Our Article.
Comments
Post a Comment