When I press the "Local Windows Debugger" button when working on any basic C++ project in Visual Studio 2013, the console opens and the program outputs, but when the console closes, another console opens, the UI changes slightly and the program outputs again.
Steps to reproduce:
Create a new C++ project
Inside the "Source Files" directory of the new project, create a file named "main.cpp"
Put a basic hello world program into the file:
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!";
cin.get();
}
Save the code and press the "Local windows debugger" button on the toolbar
A console opens, and waits until you press enter
After the first console closes, a new one opens up, and the UI changes:
Edit:
Link to download a zip folder containing the project: Test Project.zip
I had avast deepscreen enabled. To disable, goto avast user interface -> Settings -> Antivirus and uncheck the box that says "Enable Deepscreen"
On a new version of avast you need to uncheck CyberCapture option. To disable CyberCapture you need to open Avast->Settings->General and uncheck "Enable CyberCapture"
I had same problem.
Added exception to "c:\source\" where all my visual studio stuff is located.
Related
I have to do a programming project for an optimisation class, that has to be written in C or C++. So I'm trying to figure out Visual Studio 2015. I created a blank project, and opened a new C++ file, where I have the following:
#include <iostream>
int main()
{
cout >> "Hello World!/n";
cin.get();
return 0;
}
When I run it, I get a large blank white popup, and nothing else happens, even if I hit various key on the keyboard or wait for several minutes. It looks like this:
If I close the large popup, nothing happens. What Visual Studio refers to as output from build looks like this:
1>------ Deploy started: Project: LinearProgramming, Configuration: Debug Win32 ------
1>Updating the layout...
1>Deployment complete (157ms). Full package name: "53acc796-5708-4314-9034-f2a1f840a4f4_1.0.0.0_x86__eazt3av84y7ym"
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
Could anyone please explain to me what's going on? How can I create a simple C++ project in Visual Studio 2015 and run it?
I believe you selected the "Blank App(Universal Windows)" project template, which is like a Microsoft store application. What you probably want is the "Win32 Console Application" template, which creates an application without its own window (and uses the console for I/O).
This is how I create a Win32 Console Application.
Go to File->New->Project...
Select Visual C++->Win32->Win32 Console Application and name the project.
In the Win32 Application Wizard press the Next > button and be sure Console application and Empty project are selected, and then hit the finish button.
In the Solution Explorer right click on Source Files and select Add->New Item...
Select the C++ File (.cpp), name it, and hit the Add button.
After you change the >> to << add the code above and it should run.
The quick answer is to hit ctrl-f5 to open the console. After running your script and showing your output it waits for you to hit a key before closing the console.
I eventually found the answer to the question which can be seen at How to keep the console window open in Visual C++?
Hey guys I really need help.
I have recently started programming C++ again and I am trying to get Code Blocks up and running but it keeps failing because of this error.
"ERROR: You need to specify a debugger program in the debuggers's settings."
Understandably this means there isn't a debugger program so I have to download one. I tried to find the gdb.exe for MinGW but I can't find it at all. I just end up with the MinGW's Installation Manager and being left confused.
Are there any tutorials about using the MinGW written for beginners or anyone willing to help?
Thanks in advance.
Steps to add gdb.exe
Open MinGW Installation Manager
select package "mingw32-gdb" from the list.
Then select "Apply Changes" in Installation menu.
This will automatically install gdb.exe in the path C:\MinGW\bin.
Please let me suggest you debugger program TDM-GCC. For download and install visit
http://wiki.codeblocks.org/index.php?title=MinGW_installation
Because a debugger program (toolchain) is very complex undertaking, is not standard in Code::Blocks. You must download it and install on Code::Blocks.
Note: It is impossible copy and paste images here. In the case linked page changes, I, or another one, should suggest new link.
However following are instructions according to images and my experience.
Download TDM-GCC from https://jmeubank.github.io/tdm-gcc/download/ click [tdm64-gcc-10.3.0-2.exe] and run it.
In Wizard Action window - Click [Create].
In Select Edition window - If MinGW/TDM (32-bit) is not checked, check it. Click [Next>].
In Licence Changes window - Click [Next>].
In New Instalation: Instalation Directory window - If text box is "C:\TDM-GCC-32", it's okay. If is not, click [Browse ...], and navigate: C:\ > TDM-GCC-32 > click [OK]. Now text box is C:\TDM-GCC-32. Click [Next>].
If a small window appears saying The directory TDM-GCC-32 is not empty! Are you sure you want to install here?. Click [Yes].
In New Installation: Download Mirror window - Click [Next>].
In New Installation: Choose Components window - Check whether Add to PATH box is checked. Actually is checked. Click [Install].
In Installing window - Wait till [Next] become black. Then click it. Even if Instalation Failed window appears click [Next].
In Completing the TDM-GCC Setup Wizard window - Click [Finish].
Go to Code Blocks > Settings > Compiler.
10a. In Global compiler settings window click "Toolchain executables". Just below, find "Compiler's installation directory". If the below text field is C:\TDM-GCC-32, it's okay. If not, click the [...] at the end of the field. In "Select directory" wizard, navigate to C:\TDM-GCC-32. Now "Folder:" should be TDM-GCC-32. Click [Select a folder] in "Select directory" wizard.
10b. In Global compiler settings. Below red "Note:..." find "Program Files" > "Debuger". If text field reads "GDB/CDB debuger : Default", it's okay, click [OK]. If not, click the down arrow at the end of the field > choose "GDB/CDB debuger : Default". Check that text field is "GDB/CDB debuger : Default". Click [OK].
Go to Code Blocks > Settings > Debugger... . In Common window, left list, click "Default". If "Executable path:"'s text field is "C:\TDM-GCC-32\bin\gdb32.exe", it's okay, click [OK]. If not, click [...] button and navigate C: > TDM-GCC-32 > bin > click gdb32 (or gdb32.exe) file > click [open] in "Select executable file" wizard. "Executable path:" should be C:\TDM-GCC-32\bin\gdb32.exe. Click [OK]. Now you can debug your program.
If Debugger does not function, close Code Blocks and restart them.
Regards.
Hey guys I suggest a better way. Download "gdb.exe" from the Internet and copy it to the below path.
C:\MinGW\Bin
It's really works. I did it.
I have a problem, when I try to open my Hello World.exe file (that I created by following a tutorial). It immediately closes without giving me the chance to read or see if I have done everything correctly.
As you can see, I need help on how to keep it open, without instantly closing.
You can either put a break point before the end of main or try the following:
int main()
{
//...
std::cin.get();
return 0;
}
It is going to wait for you to press some key to exit the console.
EDIT: It is better to add break point which do not change existing code.
In console applications there are a couple of things you can do to stop the window from closing on you such as using system("pause") (not so recommended though), getch(), std::cin >> x etc at the end of the application.
Another option is to start a cmd window, cd to the location of the exe and run it like any other console application is meant to be ran, that way it wont just close on you, it'll simply exit.
In VS2017, you can specify that the executable is a Console app, not a Windows app. This makes your application run in a "Microsoft Visual Studio Debug Console", with "Press Any Key To Close This Window" appearing at the end of the console output:
Right click the project to bring up Properties.
Linker > System > Subsystem > Select "Console".
Press Apply before closing.
I've been trying to use Eclipse CDT to do some c++ examples, i can run them just fine with the run command, but whenever i try to Debug, the console window freezes up, I'm able to input, but the program doesn't continue.
When I debug, i get the following output on the console window (no breakpoints, but breaks on main because of default settings):
Hello, world
put your name: 15^running
The continue button is disabled and doesn't do anything when I input something and hit enter. The 15 is a random number, sometimes its 16, 20 etc.
If I run the program under eclipse I get the input prompt just fine:
Hello, world
put your name: test
Hello test
this is the code I try to debug:
#include <iostream>
#include <string>
int main() {
std::cout << "Hello, world" << std::endl;
std::string name;
std::cout << "put your name: ";
std::cin >> name;
std::cout << "Hello " + name << std::endl;
return 0;
}
My path var:
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\Java\jdk1.6.0_14\bin;C:\MinGW\bin
Eclipse version: Helios Service Release 2
CDT version: 7.0.2
OS: windows xp
GDB version: GNU gdb (GDB) 7.2
How can I debug this small example under CDT, without issues?
15^running looks as a result record from gdb's Machine Interface. Normally it shouldn't appear in the Eclipse console.
I recommend trying a different Create Process Launcher. It can be changed in the following way:
In Main menu choose "Run" -> "Debug Configurations...".
In the opened "Debug Configurations" window shown below click "Select other..." opposite "Using GDB (DSF) Create Process Launcher".
In the opened "Select Preferred Launcher" window shown below check "Use configuration specific settings", select "Standard Create Process Launcher" in the list below and click OK.
Now go to the Debugger tab in the "Debug Configurations" window, select debugger, e.g. "MinGW gdb" and click Apply.
With the Standard Create Process Launcher I am able to debug your program although "put your name:" is printed only after I type something and hit Enter, because the output stream is not flushed.
Try having a look at this http://www.cprogramming.com/gdbtutorial.html and see if that helps. Like can you press CTRL-C to break?
Also Cannot enter input with gdb. Help! might be a pointer although related to apple.
the following is from the Eclipse website's FAQ:
http://wiki.eclipse.org/CDT/User/FAQ#Eclipse_console_does_not_show_output_on_Windows
Eclipse console does not show output on Windows In Eclipse CDT on
Windows, standard output of the program being run or debugged is fully
buffered, because it is not connected to a Windwos console, but to a
pipe. See bug 173732 for more details. Either add fflush calls after
every printf or add the following lines in the start of the main
function:
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
Seems like an expected bug on windows.
When I write a program using C++ and I want to run it, I can't catch the console window. I press CTRLF5 and it does not work.
I want the window to stay open and wait, even it finishes executing. Can anyone help me?
Thanks in advance.
http://connect.microsoft.com/VisualStudio/feedback/details/540969/missing-press-any-key-to-continue-when-lauching-with-ctrl-f5
In the older versions it would default to the console subsystem even if you selected "empty project", but not in 2010, so you have to set it manually. To do this select the project in the solution explorer on the right or left (probably is already selected so you don't have to worry about this). Then select "project" from the menu bar drop down menus, then select "*project_name* properties" > "configuration properties" > "linker" > "system" and set the first property, the drop down "subsystem" property to "console (/SUBSYSTEM:CONSOLE)". The console window should now stay open after execution as usual.
try using system("Pause"); as the last line on your code (before the return of your main function)
Ctrl+F5 should work. Just in case, if you have the source of your program, add the following just before the closing brace of main.
int x;
cin >> x;
the program will wait for you to enter some value.
If you want a breakpoint to be triggerred in debugger, do simple F5 instead of Ctrl+F5, after putting a breakpoint on the relevant source line (assuming the source/debug symbols are available)
Sorry to say, Ruba, but it looks like Microsoft removed this nifty little feature when moving from VS2008 to VS2010.
I can't find anything on MSDN, the web in general, or VS options to turn it back on.
My advice is to bypass the environment altogether for testing your application. Simply open a cmd.exe window in your runtime directory (debug or release or whatever), build the executable within the IDE then switch to the command window and enter testprog.exe to run your program.
Make sure you include any required command line parameters and, after you've entered it the first time, you can just use the up-arrow to retrieve the last command.
Yes, it's a bit of a pain but, until someone comes up with a better solution, it's probably the best way to ensure you see all the output while ensuring the program has shut down completely.
Just set a breakpoint at main()'s closing curly brace if you want to see the console after the program is finished.
You should create VS 2010 C++ Projects as below:
New project -> Visual C++ -> Win32 -> Win32ConsoleApplication
In this way you will be getting "Press any key to continue..." when you run program with ctrl+F5, as it was in VS 2008.
EDIT :
New project -> Visual C++ -> Win32 -> Win32ConsoleApplication -> Next -> Check 'Empty project' -> Finish = what you actually need.