How to Run a Darn C++ File on Windows, Finally
Tags: cpp, vscode, beginners, tutorial
Published: 2023-05-14 21:36:40

I made this because while there are a lot of tutorials to configure C++, and none of them worked straight through for me. So I wounded up having to combine info from different tutorials. So hence I made this one tutorial that will hopefully work all the way through. If not, let me know. 

There are a lot of ways - this is the way that worked for me:

1) There are a lot of IDEs you could use - I'm gonna say use Vscode because that is probably the one you already have.

2) Install these plugins - C/C++

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/95i4wz6juoqea8x9c5n7.png)
and
Code Runner
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qg117cvlri7nqlcouhk.png)

I would let them install completely first before moving on to keep things simple.

3) If you already have Visual Studio installed, you can use it to install C++. But if you don't or don't want to wait for the half hour it takes to open, instead go to https://visualstudio.microsoft.com/downloads/#remote-tools-for-visual-studio-2022
and then download the build tools.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0c5a1qkajhddm63iy9f.png)

4) Open that up, and install C++. It will take forever to download, but it still beats the alternatives I guess.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9b56rhyn9ylrcd14ai2.png)

5) Now this part is the part that took some work to figure out, so thank me later - open up Developer Command prompt for VS 2022:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5anxitwg7cysd7axnvq.png)

6) Type cl to make sure everything is kosher up to this point. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahmf07wk5o0psit4dvoz.png)

7) Now create a hello world project to test your installation.
In my case, it is just in a "~\devl\C++\helo_world" (I dare you to comment on the misspelling).

8) Make a file with this basic program: 

```
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    for (const string& word : msg)
    {
        cout << word << " ";
    }
    cout << endl;
}
```
save it and close out of visual studio code - **don't skip the closing out.** 

9) Go back to your Developer Command prompt for VS 2022 and navigate to the folder where your hello world project is. Type `code .`. This will open it up in VScode.

10) Click the Run button and it will ask you to configure it. Or, press the gears icon next to the run button and select this first option you see here (I'm not typing all that out):

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2vtk4jws1i4jacswmxwu.png)

This is the screen you want to get to - there are multiple ways to get here, and the ways seem to change frequently, but this is the
destination. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/esf30w75d0yifln9cmre.png)

This screen is called "Edit configurations (UI)":

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hrpd4b7jg8ghh296x04f.png)


11) Hit the dropdown arrow - you will need to have it pre-filled. If you don't see anything something is wrong and you will need to retrace your steps. 

12) I selected one of the options that had `x64`. I am not sure why there are four of them, and what they all mean to be honest. I just know I got it working. Get used to that in tech (especially with C++). 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydtqpzm72std2w2mpvvg.png)

13) NOW you should be able to just run it. Because it is C++, it creates a whole flurry of files:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0e8q7wn7s5ry02k14lw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njf6hurs2ntgu7txbnax.png)
The .exe is the end goal. 

Bonus: If you were to run it again, it gives an error. I think it really is just confused because there is already an .exe. 

By the way, with the C++ code I gave you, if you run that .exe by just double-clicking on it, it will seem to do nothing. It is actually running, just very quickly. VScode adds the `Press any button to continue...` for the developer's comfort

Now go brag to all your friends that you are a C++ madlad/lass.