Setup vscode for Getting started with C++ on Windows

Anshul gupta
DSC KIET
Published in
3 min readJun 23, 2020

Tooling is a crucial step when it comes to productivity. In this article, we will see how you can configure your vscode like a pro 👨🏽‍💻.

If I talk about macOS or Linux, it’s really easy to setup vscode for coding in C++, but as a window’s user 😓, I can understand the pain of configuring the same. There are multiple configurations for it, but I will talk about the one that my community and I have been using for quite long.

If you don’t have vscode installed on your machine, download and install vscode from https://code.visualstudio.com/.

Step 0: Go to http://mingw.org, click on Downloads and download mingw-get-setup.exe file and install MinGW and select gcc-g++-bin. Now, Add the path of MinGW to the environment variable.

  • Search Environment Variable in windows menu.
  • Go to advance, click on the Environment Variables.
  • Open path and add the new path as c:/mingw/bin/.

Alternatively, you can also install Cygwin.

Step 1: Open vscode, click on the extensions option in the side-menu or press Ctrl + Shift + X. Type c++ in the search box, install C/C++ and C++ Intellisense extensions. Then, install Code Runner extension to get started.

Step 2: Create a folder(recommended to organise your codes in a single directory).

Step 3: Create a file with extension as .cpp under the same folder.

Step 4: Create two separate files. One for input as input.txt and the second one as for output as output.txt in the same folder.
You can use these files to store your input and output beforehand.

3-window setup: The above gif shows how you can display your code file, input and output file on the same window.

Step 5: Add a few lines to sync your input and output files.

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

It reads the input from input.txt and writes the output to output.txt only if you are running the program on the local machine, but if it’s an online judge it will not open those files.

Step 6: Write the code into your .cpp file and click the run button or Ctrl + Alt + N.

Step 7: Voila 🚀!, enjoy coding on your local machine.

We have created a list of useful resources that may help you while learning Data Structures and Algorithms. Check them out on our GitHub.

You can follow us on Twitter and Instagram to get updates about our latest activities.
Get connected with me on twitter to have a chit-chat.

--

--