User Input in VS Code with Code Runner Extension - MrAboutTech

Breaking

Wednesday, October 28, 2020

User Input in VS Code with Code Runner Extension

 

User Input in VS Code
Logo Credits: Microsoft

Most programs need user input and so you need to have a way to get user input while you are running your program. In VS Code, all the programs, by default, run and display the output in the Output section.


The thing with the output section is that it is a read-only section and you will not be able to input any value from that and if your application asks for user input and if it is running in the output section then your program will be stuck waiting for the user input.


read only output section in vscode


The solution to this is that you will need to run your code in the integrated terminal instead of the output section.


The good news is that you can do that by using an extension called Code Runner. And by just clicking on one checkbox, you can make it possible.


Things you need

l  Code Runner Extension



Code Runner Extension


code runner extension


If you have this extension then just go on to the next step and if not then you will need to install the code runner extension. Just search Code Runner in the extensions section search bar and install it.


search code runner


After installing the extension, open Settings by going to Files > Preferences > Settings or you can use the shortcut keys Ctrl + ,


vscode settings


Now in the search bar there, just search for code runner and you will see all the settings related to the extension.


vscode settings - search code runner


Then scroll down and search for the Run In Terminal checkbox.


code runner - run in terminal


Check it and that's it. Now try to run your program.


code runner - run in terminal checked


It should run your program in the terminal instead of the output section and you will be able to give any input to your program.


C Program Example


c program input

c program output




1 comment:

  1. This article contains a lot of valuable info. I am amazed by the quality of the info and also it is a beneficial article for us, Thanks for share it.Hire a hacker

    ReplyDelete