Running c++ code on visual studio

running c++ in visual

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 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 in our pc or laptop.

When you click on your gcc.exe file you have the image like something below

gcc installation

after that click on accept, when you click on accept you have the image like something below

gcc installation step -2

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.

complete gcc installation

on the succesfull installation click on the finish then, you have to log off your system.

To check GCC is installed or not open command, by click 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.

gcc version 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.

write code in visual studio code

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.

choose gcc in visual studio code

when you choose the second one it will compile your program and create a file named as test.exe in the same folder.

c++ code compilation

Now to execute your program open a new powershell and write .\test it will execute your code.

executing c++ code
0 0 votes
Article Rating

Do you want to hire us for your Project Work? Then Contact US.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x