visual studio
September 24, 2008 2:02 PM   Subscribe

The command window (in XP) flashes for just a second and then goes away when executing "Hello, World!" program written in Visual C++ express edition.

I started with Win32 project, then Console Application, put in source code and built the solution (F7), and everything seemed to be going swimmingly, then of course, I tried to execute it using F5 (and by going to project folder in explorer and Debug-->start debugging. Pretty sure this isn't relevant, but here's the source code:

// Ex1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include


int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Hello, World!\n";
return 0;
}

posted by amsterdam63 to Computers & Internet (10 answers total)
 
It sounds like things are working as they should. Your application finished, so it goes away. What you want to do is, after building with F7, open a command window, navigate to the location of your exe, and run it there. That way you have a persistent command window, and can see your print out.
posted by nomisxid at 2:13 PM on September 24, 2008


what is the problem? it probably executes. you may need a pause in there. otherwise it just executes and is done.
posted by Amby72 at 2:14 PM on September 24, 2008


It sounds like it's working normally: when you run a console application, it will open a console window, run, then the window will go away afterwards. Since your application runs very briefly, the console window will just flash and vanish again, too quickly for you to see the output.

If you can make an EXE of your application and place it in a known location, you can pop open a command window, CD to that location, and run the EXE there from the command line - then you should see your "Hello, World!" output.

There also may be a way to have Visual Studio preserve the console window after the application runs, but I'll leave that question to the Visual Studio gurus.
posted by pocams at 2:14 PM on September 24, 2008


4thing the command prompt suggestion.
posted by owtytrof at 2:26 PM on September 24, 2008


put in system("PAUSE");
posted by alkupe at 2:28 PM on September 24, 2008


Looks like everything is working OK. You may want to put

getchar();

before your return statement. This will wait for something to be in the input stream before going to the next line and completing the execution of your program.
posted by demiurge at 2:34 PM on September 24, 2008


Run it with "Start without debugging" from the debug menu or equivalently by pressing ctrl-F5.
posted by TheSlate at 2:36 PM on September 24, 2008


TheSlate has the best answer so far. Programs run from inside the debugger (F5) will exit immediately upon main finishing; programs run outside the debugger (Ctrl+F5) will show the "Press any key to continue..." message. If you want to run your program in the debugger and not have it exit immediately, put a breakpoint (F9) on the closing } of your main() function
posted by 0xFCAF at 2:40 PM on September 24, 2008


Ok, thanks a lot. Its just I'm reading a book, and the book made it seem like it should stay up instead of just flashing. All of those solutions worked, and I really appreciate all the help.
posted by amsterdam63 at 2:42 PM on September 24, 2008


Open command window here is your friend.
posted by damn dirty ape at 3:01 PM on September 24, 2008


« Older How do I learn the Visual Studio way of thinking...   |   Alien books. Newer »
This thread is closed to new comments.