In this article, we will learn about how we can run c++ code on visual studio. As we know demand for visual studio code is increasing day by day by coders.
So I will tell you how we can run c++ code in visual code.
Those who want know-how to run the program in notepad++ please click here
We will follow the below steps
- Download and Install GCC
- Download and Install Visual Studio Code
- Run the c++ code in visual studio code
Step: 1 Download and Install GCC
To install the GCC for 64-bit windows click here and if want to install GCC for 32-bit windows click here. If you want to check your window is 32-bit or 64-bit please click here.
Now we will Install GCC on our pc or laptop.
When you click on your gcc.exe file you have the image like something below
after that click on accept, when you click on accept you have the image like something below
when you click on install, it will have something like the below installation image.
on the successful installation, it will have something like the below image.
on the successful installation click on the finish then, you have to log off your system.
To check GCC is installed or not open command, by clicking windows+r then write cmd and press enter after that your command panel will open.
In your command panel write gcc –version it will show your version which is installed.
Step: 2 Download and install Visual Studio Code
To install the visual studio code please click here after the download, click on your .exe setup and install in your windows.
Now open you visual studio code and look for c++ extension install the extension.
Step: 3 Write c++ code in visual studio
Now we will write c++ code in our visual studio code, create folder named as learn-cpp and now create a file named as test.cpp under that folder.Now write the below code in your test.cpp file.
#include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; // This prints Hello, World! return 0; }
The above code will return you Hello, World as the output.
To execute the code in visual code press ctrl+shift+b then something like below will be open in your vs code choose the second one.
when you choose the second one it will compile your program and create a file named as test.exe in the same folder.
Now to execute your program open a new powershell and write .\test it will execute your code.
One Comment