Menu

Comman Prompt Dissapears

Vertoc Nep
2009-06-11
2012-09-26
  • Vertoc Nep

    Vertoc Nep - 2009-06-11

    I am running Dev C++ 4.9.9.2 and running OS Windows 7 RC
    I am trying to get a command prompt show the string "C++ is power programming."
    The problem is that it works. The command prompt window show up and it says those exact words. Then it dissappears in less than a second. Here is the code, also i tried another string with new code but that did not work either:
    /
    This is a simple C++ program
    Call this file Sample.cpp
    /

    include <iostream>

    using namespace std;

    // A C++ program begins at main().
    int main()
    {
    cout << "C++ is power programming.";

    return 0;
    
     
    • cpns

      cpns - 2009-06-11

      As for all programs running under Windows, when the program terminates, its window is closed by the OS. You would not want it any other way, otherwise you'd have a screen full of zombie windows!

      But despite this normal behaviour people always seem to be surprised when it happens to their own code! This miscomprehension is so common in fact, it is dealt with in the "PLEASE READ BEFORE POSTING A QUESTION" thread of this very forum.

      Now your phrase "I am trying to get a command prompt show..." is very telling. The 'command prompt' specifically refers to the 'ready for input' indicator in programs such as cmd.exe (the Windows command shell). cmd.exe is an example of a 'console mode application'. Your program is also a 'console mode' program, and nothing to do with "command prompt".

      Incidentally, if you did run your program from within cmd.exe, it runs as a child of cmd.exe and so the window will not close until cmd.exe terminates, which you have to do by taking deliberate action such as the 'exit' command. There's a clue to your solution - write your code so that some deliberate action has to be taken to terminate.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.