Can't get Hello World to print in Visual Studios 2019

Hello all,

I recently downloaded visual studios 2019 and am running into an issue that I could not find a solution for after hours of research. I am trying to print a simple hello world to console. I can not get it to print correctly no matter what I do. Picture attached shows the code I am using.

The error is that every time I hit ctrl+f5 to run it, the console comes up but displays partial messages followed by the "Press any key to continue" prompt.

The messages displayed read "with code 0" (as pictured), or just a 0, or just a period. I have uninstalled and reinstalled many times and also tried the 2017 version of the program

Thanks for any help

https://imgur.com/a/yKanXnk

Last edited on
The program is finishing. This is not unexpected behaviour. What happens if you run it with just F5?

Or even better, don't run it through Visual Studio. What happens if you locate the executable being built and run it from the command line?

Or what if you put something in your code to make it not finish until you're ready. For example:
1
2
std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
Last edited on
Hello, thanks for the reply!

I seem to have fixed my problem bu adding cin.get(); before my return 0. The problem was that my console was closing itself.

However, now that I am able to get this to display, it is no longer displaying the "press any key to exit" message. Is this usual? Pic included

https://imgur.com/a/rjz0pWn

Thanks!
There is nothing wrong with the output of your program in VS 2019, it looks like you've scrolled the console window so the earlier parts of the output have scrolled up past the top of the window.

No need to use get or ignore to artificially keep the console window open when running the program within the IDE, VS is already doing it for you.

Your code from my VS 2019:
Hello World!

C:\Programming\My Projects 2019\Project1\Debug\Project1.exe (process 8296) exited with code 0.
Press any key to close this window . . .

All the text before the (Process.....) is simply the absolute address of where your program is located.

Exiting with code 0 means the program ended normally, no crashes. return 0;
Adding std::cin::get forces the program to wait until the user enters something and then hits enter/return.

There is a stickied topic here in the Beginner forum. I suggest you take the time to read through all the pages.

http://www.cplusplus.com/forum/beginner/1988/
Hello maxib123,

As Furry Guy pointed out there is a way to set the IDE to have this show up at the end of a run:
Hello World!

C:\Programming\My Projects 2019\Project1\Debug\Project1.exe (process 8296) exited with code 0.
Press any key to close this window . . .

Using the wizard to set up the solution I have found this happens at the end of the program. But when I create an empty project it is not there.

Since I do not use this I am not sure what needs changed in the IDE. Maybe Furry Guy would know?

What I do use quite often is:
1
2
3
4
5
6
7
8
	// A fair C++ replacement for "system("pause")". Or a way to pause the program.
	// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue: ";
	std::cin.get();

	return 0;  // <--- Not required, but makes a good break point.
}  // <--- Closing brace of "main". 

If line 3 becomes a problem just put a comment on it.

Hope that helps,

Andy
Last edited on
there is a way to set the IDE to have this show up at the end of a run

That is by default when launching the console program from the IDE (F5 [debug] CTRL+F5 [no debug]), and it can be turned off when launching a debug (F5) session. The "program pauser" is still active in a release (CTRL+F5) session, though you don't get all the program executable location and exit status output.

It doesn't matter how the console project is generated with the default setting, via wizard or as an empty project, VS will use their "program pauser" when the program ends. Normally or abnormally.

To not use the "program pauser" feature: Tools->Options->Debugging->General. Fourth option from the bottom, "Automatically close the console when debugging stops"

Personally I wouldn't recommend it. Or adding all this extra code to pause execution.

http://www.cplusplus.com/forum/beginner/1988/

Either run your program via the VS IDE, or in a command prompt console window.

As I said, it looks like the console window text was scrolled out of the window at the top. All the verbiage is there, just hidden. Try moving the scroll bar at the right up.

+----------+

Windows 10's File Explorer allows for an "easy" way to launch a command prompt. Click in the address bar, highlighting all the address. Type "cmd" and press enter.

You now have a command prompt opened with the address already entered.

Win10 allows you to drag and drop .exe files into the command prompt window, with the absolute adress as part of the file name. Hit enter, your program starts and finishes. The command prompt window stays open!

A command prompt is a Windows GUI program, so you can close it by clicking the X in the top right corner.

Or entering "exit" (without the quotes) and hitting enter.

I seem to remember earlier Win versions allowed this as well.

If I don't run a console program via the IDE I use a "cmd" command prompt. No code needed to artificially keep a console window open.
Last edited on
Topic archived. No new replies allowed.