title: How to compile and run a c++ source file in visual studio code
body: <p>I've searched for an answer to this question, but couldn't seem to find one. I know that we can use task.json files to automate the build process. But I want to use Visual Studio Code to implement algorithms in C++ for competitive programming. I want to be able to compile a program, and run it all in one go, if there aren't any errors. If there are errors, I would like them to be displayed. </p>
  
  <p>Also, visual studio code comes with an integrated terminal, so it would be nice if the program output could be redirected there. 
  Also, how can we map a keyboard shortcut to run this task. </p>
  
  <p>I'm using Visual Studio Code 2019 on Windows 10 with the MinGW G++ compiler. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've tried Escape0707's answer below, and I tried executing <code>'Run Code'</code> with the default key binding of <code>Ctrl + Alt + N</code> but I'm getting this error. </p>
  
  <p><a href="https://i.stack.imgur.com/R6yY6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R6yY6.png" alt="enter image description here"></a></p>