How to put out a Dos screen once you build in Visual studio? - c++

I'm pretty new to programming and I have built my program a few times. However I can't figure out how to make a Command Window or DOS window show up, even after the build has finished in Visual Studio on Windows.

Suppose you have built your program as a 'Console app' or 'Command-Line app' in Visual Studio. These were choices you made when you first set up your project. Then, running your program from Visual Studio will cause a Command Window (DOS like) to display, and your program will start within this window.
The 'Debug' menu item has 'Start Debugging' and 'Start Without Debugging' - either choice will run your program.
Depending on your version of Visual Studio or your configuration options, Visual Studio may close the console window as soon as the program completes. This is not the default behavior on recent Visual Studio options, but you may miss the Console Window popping up and going away if it is happening to you. Likewise, it may be hidden if the Console Window is not displayed as the top-most Window.

Related

How to run C/C++ code using integrated terminal in Visual Studio

How to launch a C/C++ console application using the integrated terminal in Visual Studio instead of launching a separate terminal window?
To clarify more:
When I press the run button right now, this is what happens:
But what I want is something like this (but it must happen when I press the run button), where the output is directed to a terminal inside the visual studio window, without launching a separate window, this will make it easier when debugging because I won't have to switch between multiple windows:
There is a handy VsConsoleOutput extension for Visual Studio 2019 / 2022 that redirects program output into Output window inside of Visual Studio.
However when installing it i've got an exception complaining about incorrect value of InstalledByMsi value somewhere in manifest. The workaround is to manually open downloaded .vsix package (which seems to be a .zip archive) using WinRAR or something, adjust one line in extension.vsixmanifest file and save updated archive.
<Installation AllUsers="true" InstalledByMsi="false">

Why does a program that is getting debugged in Visual Studio take focus and not allow me to alt-tab back to VS?

I am trying to debug an application and look at the code while a test runs, but while that test is running the focus is forced on only the application. I can't alt-tab from it back to Visual Studio, because it forces back the focus. How can I look at the code and allow a test to run without it taking focus? This is in C++ and this is not an instance where a breakpoint is being hit

How to display Visual Studio Console Application output inside the IDE and not in command prompt?

I recently started C++ programming on Visual Studio and I noticed that it always gives me the console output in the command prompt (CMD).
I am a java programmer and I'm used to working with Eclipse and Netbeans. With those IDEs, I was able to see the console inside the IDE and not in a different separate window.
Is there a way to display the console output inside Visual Studio, like Eclipse and Netbeans do?
It's infuriating. I spent hours looking for this. Visual Studio doesn't have command prompt inside the IDE.
They have it for Visual Studio code - Intergrated command prompt. But not for visual studio 2015 Enterprise. So, in other words, microsoft has command prompt terminal inside the free version of visual studio but not for the paid version
Unfortunately, the answer seems to be no.
In Visual Studio, console applications are displayed on the command prompt and not inside Visual Studio itself. Meaning that Console.WriteLine method and similar ones write your output to the console window because your application type is Console Application.
You are able to write output to Visual Studio itself by using System.Diagnostics.Debug.WriteLine as mentioned on MSDN. That will cause the debug output to appear in the Output Window inside Visual Studio. In case you don't see that view, you can choose to show it by Debug => Windows => Output.
You should bare in mind that this is not what you asked for.
This "solution" is helpful just in case you want to debug parts of your code and don't want to open the command prompt but just see the relevant output inside the IDE.
In addition, you won't be able to give input back in this output view.
The most important thing, you will not be able to execute your application correctly outside of your coding environment. So, it will work only on the IDE but you won't be able to see this output when the application is on its own (as it meant to be as a console application).
Another solution, that you might like, is to work with Eclipse.
You said that you are familiar with Eclipse as a Java developer and now you work with C++ and don't get along with Visual Studio so far.
So, you can download Eclipse IDE for C/C++ Developers.
In there you will be familiar with the IDE and you will be able to display your output inside Eclipse without any weird and unnecessary workarounds.

Why does Visual Studio treat ANSI Escape codes differently when debugging?

Applies to:
Visual Studio Community Edition 2015 (C++)
Windows 10
Visual Studio has two ways to run a C++ program for Win32 Console: "Start Without Debugging (Ctrl+F5)" and "Start Debugging (F5)". Both will launch a separate console window for the program. If the program sends ANSI escape codes via cout, the first window works as expected, but the second will show the codes as characters, with unprintable codes such as ESC replaced by a question mark in a box.
Why is it different? Is there a way to get the ANSI escape codes to behave normally while debugging?
The 2015 documentation does not say that there is a restriction (earlir versions required the paid version).
With Visual Studio, you can use the debugger to attach to a running process, which would avoid the problem — provided that your program can initialize and wait for you to do this.
As for why it is different, that is probably because the debugger is intercepting the input/output of the program running in the console window (and preventing it from changing the I/O modes).
Further reading:
Attach to Running Processes with the Visual Studio Debugger (2015)
How to: Attach to a Running Process (2010)
From followup comments, #Sean-Gugler realized that
the executable's ANSI codes were not interpreted when it is run natively (e.g., opening from the File Explorer),
but worked when run normally from Visual Studio.
On being reminded that Windows 10 console window interprets ANSI escape sequences,
he verified that the executable ran as expected in a console window, and
surmised that Visual Studio was running the executable directly (without a console window) when debugging (F5), but did run it in a console window when running the executable normally (ctrlF5).
One of the problems in starting a console application from a GUI (such as Visual Studio) is that the application would have to do some extra work to allocate a console.
Further reading:
Can one executable be both a console and GUI application?
Using the console in a GUI app in windows, only if its run from a console
How to write to the console in a GUI application

Want to open command prompt when running a program in visual studio community

My visual studio community 2015 are opening a MFC program when I hit RUN. All over youtube, everyone has command promt automatically opening when hitting the RUN or Local windows debugger button. I want to change it to command promt aswell, does anyone have a solution?
(beginner)
It seems you created an MFC project and when you start this, of course you start an MFC program.
If you want a console application use File->New->Project and select the Win32 console project template.
See this MSDN article for more information.