C++ On Visual Studio Code

Ever wondered to have a good IDE for C++ with beautiful dark theme and essential features? Stuck on editors like DevC++ & Codeblocks?. Well, If you are familiar with VSCode, and if you want to write some C++ Code for Competitive Coding, then this blog is for you.

SETUP

DEBUG HELLO WORLD

SETUP

Mingw-w64 Setup Settings:

Version: Latest

Architecture: Run Following command in cmd:

systeminfo | findstr /c:"System Type:"

If Output is x86-based PC select i686

else if output is x64-based PC select x86-64

Threads: posix

Exception: seh

Build Version: 0

DEBUG HELLO WORLD

  • Create a new folder Hello World and create helloworld.cpp in that folder. Open that folder in vscode.
#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;
}
  • Go to Main menu > Terminal > Configure Default Build Task > g++.exe build active file (if not shown, restart vscode)
  • Open helloworld.cpp and press ctrl + shift + B to build
  • Press F5 > Run > Add Configuration… > C++ (GDB/LLDB) > g++.exe build and debug active file
  • Open launch.json just created by above step and do following steps:

1) Add following configuration: "targetArchitecture": "x86_64" [2]

2) Change following configuration: "externalConsole": true

  • Add a breakpoint and debug

REFERENCES