Using Dev-cpp, a small program compiles but the resultant .exe file
does not run. From the DOS command, it runs. When I try from the
windows run command , it flashes but immediately goes away.

Recommended Answers

All 6 Replies

Using Dev-cpp, a small program compiles but the resultant .exe file
does not run. From the DOS command, it runs. When I try from the
windows run command , it flashes but immediately goes away.

try ./filename

try ./filename

What does this do?

cin.ignore(); // this ignores one enter key

or

system("pause"); 
// should use cin.ignore but you can use this
// it displays: "Press any key to continue..."
// and when you press any key, it continues...

or as veron was saying

// Before using this make sure you have included: #include <windows.h>
Sleep(1000);
// the amount you put is in miliseconds, 1000 = 1 second
// this will wait the amount of time you put into before moving on.

put that in, and you will press enter before the window closes..

atm it is running correctly but it doesent know you want it to wait till you want to end it, so you have to add that.

Small programs usually run in command prompt...if you want it to have its own window, that's a different matter.

cin.ignore(cin.rd_buf()->in_avail());
cin.get();

Slap that on the end of the code. This will do the following:
ignore all the available input from the cin (console) input buffer, then grabs a null terminated character (basically waits until you hit enter).

commented: Elegant use of ignore+buffer I hadn't seen before. +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.