VS Code - Failing to take input from terminal - c++

I am fairly new to tweaking with the settings in VS Code. I have installed the code runner extension on VS Code. I have also updated the settings to make the code run in terminal, instead of the output tab.
This works fine with other languages, but in case of C++, it fails to take inputs and finishes execution as soon as it compiles. What could be causing this?

Go to settings in VS Code, and look for the property "Run in Terminal" under Code Runner settings. Check that box, and update your compiler directory. Once you do this, reload the VS Code window and run your code again, the terminal should take inputs now.

Related

Running custom commands with VS Code and CMake Tools

I am using VS Code with the CMake Tools extension, and I would like to run a simple MPI program. Everything compiles just fine, and I can run my code in the terminal using
mpiexec -n 6 "path-to-my-workspace\build\my-executable.exe"
However, I would like to set things up so that this gets executed automatically when I press Control + Shift + P > "CMake: Run Without Debugging" (or Shift F5).
I read in the CMake Tools documentation that I could create new launch targets in a launch.json file. However, the VS Code documentation states that
The launch.json file is used to configure the debugger in Visual Studio Code.
I want this for debug, but also for release. Should I still use a launch.json file? I had the same problem in the past when I needed to pass arguments to my main function. What is the right way to do that in VS Code with CMake Tools?
This sounds like two cases of terminology-related confusion.
In VS Code, there are actions to "Run Code" and "Run Without Debugging". You can find more about the distinction between the two in this question. In a nutshell, "Run Code" runs the program inside a debugger program (like gdb), and and "Run Without Debugging" also runs the program, but doesn' run it inside a debugger program.
The two most common build modes are "debug" and "release", where debug includes debugging symbols that enable running in a debugger, and release does not and instead is built with more optimizations. VS Code can run both types of builds without debugging, and can run debug builds in a debugger. For release builds, it can only run outside a debugger.
You specify that you only care to run outside a debugger.
To answer your question "Should I still use a launch.json file?", yes, you can still use a launch.json file.
Also, note:
Tip: The Run action is always available, but not all debugger extensions support 'Run'. In this case, 'Run' will be the same as 'Debug'.
Another note: If the program you wanted to run wasn't a build output of your project, then you would instead probably want to be using tasks.json.

Visual Studio Code Running Environment

I'm mostly using VSCode. I have two questions:
In the case of having a compiler error, VSCode warns you while you are writing the code (before you compile/run your program.) How I can do this?
How I can have the environment so that when I click on run button it compiles, runs and shows me the output in the terminal section?
Maybe this extension could be of help: C/C++ Advanced Lint
Install Microsoft's C/C++ extension and have a look at the documentation. Especially the topic "Create a build task" should be of interest for you (after you've done all the prerequisites steps.

Qt Application not running

I am trying to run a simple "Hello, world" console application but I am experiencing some errors when compiling that I am not familiar with. I have done a bit of research into similar problems with Qt but I haven't been able to find a solution. The closest solution I have come across was to change my Patch Command setting under:
Preferences -> Environment -> System -> Patch Command
to
usr/bin/xterm -e
However, when I try to do this it goes red indicating that I do not have this file.
Environment Preferences Window
The following image is a screenshot of what is displayed in the terminal window when attempting to compile my project.
Console Application Output
Any help on this problem would be much apprectiated! It is very frustrating having something like this hold me back!
Don't run your project in a terminal unless you actually select a working terminal, and that's all. The patch command is irrelevant in this anyway - it's not the terminal, but the patch command -- used to patch source code. You don't need it unless you explicitly use code patching. Go to Projects (Ctrl-5), click on the active Run configuration for your project, uncheck "Run in terminal", done.

Strange behavior of Eclipse Neon

I use Eclipse with CDT plugin for my C/C++ development. And I use MinGW compiler. Environment Path set properly. All the setting done properly in Eclipse. While editing the source code its working fine but after compilation when I try to execute the source code sometimes it says it cannot open the .exe file or sometimes doesn't show anything when there is some input to take. When I stop the execution pressing the red button program gets executed completely with default values.
But everything is fine if I compile and run the same source code using notepad and the command prompt. Please help.
A common problem is that if the program is currently executing, the program file is opened by the system and cannot be reopened for writing by the compiler (or more exactly by the linker). This problem can be easily reproduced by starting the program in debug mode and stop it at a breakpoint. Then, while the process is active, change a line in source and ask for a new build: you will get the error saying that the exe file cannot be opened.
How to fix: ensure to close any possible execution of the program when the error happens and rebuild

Eclipse c++ never run when build has errors

When programming in eclipse (c++), I would like to just hit f5 (run) and have the project I'm working on save, build and (if there are no errors) run. If there are errors I want it to show the problems window and stop.
This all works at the moment except for the part where it shouldn't run when there are errors.
Is there a way to make eclipse never run the project when there are errors? Perhaps with an addon?
EDIT: Forgot to mention the prompt... The prompt does show but I want it to not show at all. If you look at the preference window you'll see that there's no 'never' option, there is one for all the other options but not for the 'launch if project contains errors'.
By default, Eclipse CDT does not run code with build errors, but maybe you have checked the option Always launch without asking checkbox.
You should go to Windows menu->Preferences->Run/Debug->Launching->Continue launch if project contains errors and check Prompt option instead of Always. Using this, Eclipse CDT will prompt you if errors exists during building or launch your binary if it has been compiled without errors.