Рет қаралды 393
How to Set Up C++ in Windows with Visual Studio Code
Step 1: Install Visual Studio Code
Download Visual Studio Code from the official website.
Run the installer and follow the setup instructions.
Once installed, open Visual Studio Code.
Step 2: Install the C++ Compiler (MinGW)
Download MinGW (Minimalist GNU for Windows) from the official source.
Launch the mingw-get-setup.exe and proceed with the installation.
In the installation manager, select mingw32-gcc-g++, which is the C++ compiler, and click on the “Apply Changes.”
Add the bin folder (e.g., C:\MinGW\bin) to your system environment Path:
Right-click on This PC → Properties.
Click on Advanced system settings.
Go to Environment Variables → Under System Variables, find Path and click Edit.
Add the MinGW bin directory (C:\MinGW\bin) and click OK to apply.
Step 3: Install C++ Extensions in Visual Studio Code
Open Visual Studio Code.
Click on the Extensions icon on the sidebar or press Ctrl+Shift+X.
Search for C/C++ by Microsoft and click Install.
Optionally, install Code Runner to run your code easily within VS Code.
Step 4: Configure C++ in Visual Studio Code
Open a new folder in Visual Studio Code for your C++ projects (File → Open Folder).
Inside the folder, create a new file with theextension, e.g., main.
Write a simple C++ program to test your setup:
using namespace std;
int main() {
return 0;
}
Step 5: Set Up Tasks and Launch Configuration
Go to Terminal → Configure Default Build Task → C++ (G++ build active file) to create a task for compiling your C++ program.
You can also set up debugging by going to Run → Add Configuration, then selecting C++
Step 6: Running Your C++ Code
Open the terminal ) and compile your program with the command:
bash
Run the compiled program by typing:
bash
./main
If everything is set up correctly, you should see Hello, World! printed in the terminal.
This setup allows you to write, compile, and run C++ code directly from Visual Studio Code in a Windows environment