12 Replies - 4303 Views - Last Post: 14 May 2012 - 03:28 PM Rate Topic: -----

#1 Yeronox  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 102
  • Joined: 12-March 12

Command prompt window disappears

Posted 14 May 2012 - 01:09 PM

Hello, I've got a problem: whenever I run my project, the command prompt window disappears and I don't know why.
My project is this: http://img163.images.../capturezjs.png
As you can see I'm a very very beginner :)

Is This A Good Question/Topic? 0
  • +

Replies To: Command prompt window disappears

#2 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,176
  • Joined: 08-January 12

Re: Command prompt window disappears

Posted 14 May 2012 - 01:21 PM

How about putting
system("pause");


or
cin.get();


at the end of your code ??
EDIT : Finally found this !! http://www.dreaminco...on-window-open/

This post has been edited by aresh: 14 May 2012 - 01:22 PM

Was This Post Helpful? 0
  • +
  • -

#3 Yeronox  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 102
  • Joined: 12-March 12

Re: Command prompt window disappears

Posted 14 May 2012 - 01:34 PM

cin.get();

It works!
Though I don't know what it means, I'm reading a tutorial and it didn't explain that :P
Thanks a lot!
Was This Post Helpful? 0
  • +
  • -

#4 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,176
  • Joined: 08-January 12

Re: Command prompt window disappears

Posted 14 May 2012 - 01:38 PM

http://www.minich.co...getfunction.htm
I guess everything is explained here...

This post has been edited by aresh: 14 May 2012 - 01:38 PM

Was This Post Helpful? 0
  • +
  • -

#5 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1363
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Command prompt window disappears

Posted 14 May 2012 - 01:39 PM

But don't use system("pause"). It's a horrible resource intensive, platform dependent way of pausing progress. What happens when you call system("pause") -

1. suspend your program

2. call the operating system

3. open an operating system shell (relaunches the O/S in a sub-process)

4. the O/S must now find the PAUSE command

5. allocate the memory to execute the command

6. execute the command and wait for a keystroke

7. deallocate the memory

8. exit the OS

As you can see, you don't want to be doing this many times.

resume your program
Was This Post Helpful? 0
  • +
  • -

#6 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,176
  • Joined: 08-January 12

Re: Command prompt window disappears

Posted 14 May 2012 - 01:44 PM

I knew it someone would say this... But this is also an easy method to pause the screen... cin.get() might not work everytime, you will have to add cin.ignore() and all... Better, just write a single line.Plus, sometimes the convenience of programmer is more important than system processing. Do you know that to display DIC on your screen, your monitor has to do how much work ?? How much processing power is wasted by your processor ?? And don't forget, our computers are fast enough to do all this and more, without any lag !!
Was This Post Helpful? 0
  • +
  • -

#7 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: Command prompt window disappears

Posted 14 May 2012 - 01:49 PM

Console applications should be called from console, no 'pause' needed.

I see you are using Dev-C++. Search a little bit and you'll see that nobody recommends it.
There are some IDEs that pauses your application to you at end (if my memory is not wrong Code::Blocks pauses it and show the returned value, pretty sweet).
Was This Post Helpful? 2
  • +
  • -

#8 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1363
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Command prompt window disappears

Posted 14 May 2012 - 01:55 PM

That's not the point. Why do something that you know is wrong? Why not do it correctly the first time? Ok it's a one line quick fix, but it's just that - a quick fix.

Also I don't care about how much work my computer has to do to display DIC, the point is I would hope that the site's creators wouldn't be lazy and waste cycles with function calls that are widely inefficient, all for the cost of a couple of lines less code and a little more readability.

Ok you have a point. For smaller programs you may as well use it, but anything after that you should stay away from it.
Was This Post Helpful? 0
  • +
  • -

#9 Yeronox  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 102
  • Joined: 12-March 12

Re: Command prompt window disappears

Posted 14 May 2012 - 01:57 PM

View Postanonymouscodder, on 14 May 2012 - 08:49 PM, said:

Console applications should be called from console, no 'pause' needed.

I see you are using Dev-C++. Search a little bit and you'll see that nobody recommends it.
There are some IDEs that pauses your application to you at end (if my memory is not wrong Code::Blocks pauses it and show the returned value, pretty sweet).

First of all, thanks for all replies!
Well, I did install it because it was the first one I 've found; otherwise, just tell me a new software and I'll take it!
There was no choice on my tutorial so I just Googled it :)
Was This Post Helpful? 0
  • +
  • -

#10 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,176
  • Joined: 08-January 12

Re: Command prompt window disappears

Posted 14 May 2012 - 01:59 PM

Even I cannot disagree with that... For larger programs, that call is totally wastage. But at least for small programs, I don't have objection using it, although I use it very rarely.
EDIT : He told you, Code::Blocks is a good one..

This post has been edited by aresh: 14 May 2012 - 02:00 PM

Was This Post Helpful? 0
  • +
  • -

#11 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Command prompt window disappears

Posted 14 May 2012 - 03:17 PM

I too recommend CodeBlocks. I suggest that you first uninstall Dev-C++.

Then download & install this version of the MinGW compiler. If you do this before you install CodeBlocks, CodeBlocks will find it and use it to compile/build your programs.

Then download & install this version of CodeBlocks.

*********************************************

CodeBlocks will hold the terminal window open, so there's no need for system calls or cin.get(), etc.


*********************************************

For people using MS Visual Studio, aresh, if the project is configured & run correctly, it too will hold the terminal window open. Here's how:

Setting up a project in Visual C++ for ordinary C++ programs (i.e., not Windows GUI applications):

Open the New Project window, select Win32 Console Application, type a project name & click OK

That opens the Application Wizard window. DON'T click Finish. Instead, click Next.

On the next window, under "Additional options", click Empty project. Now click Finish.

You now have a new, empty "console solution" ready to go.

****************************************

Adding files to the project:

The Solution Explorer should be visible, usually in a panel on the left side of your screen. If you don't see it, click View, then click Solution Explorer.

To add a new file to your project (this applies to your initial program .cpp file as well as any additional header and source files you want to add to the project), in the Solution Explorer right-click on Source Files. Point your cursor to Add, then click on New Item, then select the type of file you want to add (for beginners this will usually be a C++ File or a Header file), then near the bottom of the panel enter a name for the file, and finally click Add.

(If you want to add an already-existing file to a project, you can click on Existing Item and use the explorer window that opens to locate and select your file. However, the file should already be located in an appropriate folder for the project. Therefore this method isn't recommended for beginners unless you fully-understand the appropriate directory structure for Visual Studio projects. It's safer to let Visual Studio add a new empty file and then copy and paste your existing code into that new file.)

You can also add a file to the project by clicking Project on the Toolbar at the top of the window, then click Add New Item and then proceed as described above.


You now have an empty file in which to write your program. When ready to test your program, build it by pressing F7, then run it by typing Ctrl-F5 (that means press and hold the Control key while you press the F5 key) and the terminal window will stay open when the program finishes. (Therefore, no need to use system("pause"); or cin.get(); or any of the other "tricks" people use to prevent the program from ending.)
Was This Post Helpful? 1
  • +
  • -

#12 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5379
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Command prompt window disappears

Posted 14 May 2012 - 03:20 PM

There is a link to this question on the C/C++ faq : Holding the execution window open
Was This Post Helpful? 0
  • +
  • -

#13 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Command prompt window disappears

Posted 14 May 2012 - 03:28 PM

View Postno2pencil, on 14 May 2012 - 06:20 PM, said:

There is a link to this question on the C/C++ faq : Holding the execution window open

Sorry, but I think that thread is a colossal waste of time & beginners are likely to come away from it even more confused. Just my opinion.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1