Samuel Rodriguez
Samuel Rodriguez

Reputation: 41

How to run c++ in vscode

I cannot for the life of me figure out how to run and debug a c++ file in vscode. There are always at least one or two things wrong.

I've already used the basic tutorials, but they don't seem to work for me.

Can someone explain it to me like I am 5 years old? Or point me in the direction of a place that will? I am totally burnt out and feel like a total dunce. I can't get a hello world program running and it is driving me crazy. Any help would be appreciated.

Upvotes: 1

Views: 157

Answers (2)

  1. Make sure that you have c++ compiler I prefer mingw.
  2. Open vscode and go to Extensions or by keyboard shortcut ctrl + shift + x.
  3. Search for .run and install
  4. Search for C/C++ and install.
  5. Go to settings ctrl + ,

By GUI

settings in vscode

  1. In the search bar, search for code runner and Code-runner: Run In Terminal will be unticked by default. You tick it and close settings tab. Refer the pic for better understanding.

ticking code runner: Run in terminal

  1. Finally create a C++ file and save. Go to Terminal and select Run Build Task then click ctrl + alt + n to run the code. Again refer image for better understanding.

Run Build Task

This should work, but if still didn't work let me know. Else refer any youtube video , you might have committed small mistake. Let me know if this didn't work my dear 5 years old guy ;)

Upvotes: 0

Nemuel Wainaina
Nemuel Wainaina

Reputation: 11

Is it on Windows or Linux ? If on windows, first download and install the mingw setup. You can find it here : https://sourceforge.net/projects/mingw/ After installation, add the location of th bin of g++ to PATH so that you can access it via the command line. You can also add some extensions to your VS Code to make debugging C++ code easier, then in VS Code, open the terminal, and , while in the directory where you have your cpp file, simply do a g++ filename.cpp to compile, then run the executable, a.exe, unless otherwise specified in the previous command . Hope this helps

Upvotes: 1

Related Questions