How to Run a Darn C++ File on Windows, Finally

snelzing

snelzing

Posted on May 14, 2023

How to Run a Darn C++ File on Windows, Finally

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
and
Code Runner
Image description

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

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

Image description

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

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

Image description

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;
}
Enter fullscreen mode Exit fullscreen mode

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

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

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

Image description

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

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

Image description

Image description
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.

💖 💪 🙅 🚩
snelzing
snelzing

Posted on May 14, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related