Thread: my dos closes at once

  1. #1
    Unregistered
    Guest

    my dos closes at once

    I downloaded a compiler bloodsheft or something and copied and pasted some tutorial stuff into it. "Hey you im alive and oh hello world"
    well i did that it all worked but when i open the .exe it opens for a milisecond and then closes again?
    I can read the sentence for a sec so i did that right
    But what's up?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Go to the C board. All your questions will be answered.

    ps::system("PAUSE")

    should work.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Unregistered
    Guest
    #include <iostream.h>
    int main()
    {
    cout<<"HEY, you, I'm alive! Oh, and Hello World!";
    return 0;
    }

    where do i put that then? p

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You printed a string and then instructed the system to "return" to the calling environment, which in this case would be the OS I suppose, and so to answer your question, before you call return.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    12
    this always works, i use DEV all the time
    #include <ioststream.h>
    #include <stdlib.h>

    int main () {
    cout<<"Hello World!";
    return 0;
    }


    always be sure to include that stdlib.h ..... i read about it in the Dev C++ help file
    THE Dark_Knight_506

  6. #6
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125
    Like I previously posted a couple of days ago:

    return 0; at the end of main should freeze the DOS window, but in some cases in doesn't.

    What you should do in order to see the output is open a DOS window and run the program from inside the DOS prompt. The difference is:

    The way you do it - you open a DOS exe in Windows environment, it runs, it finishes running, Windows closes the DOS windows for you.

    The way you should try - open a DOS windows, go to the directory where the executable you want to run is stored, run that exe. In this case the program runs and stops running inside the DOS window that is under your control (since you opened it) and Windows cannot close it unless you tell it (or Windows crashes, whichever comes first).

    Hope this helped.
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

  7. #7
    In The Light
    Join Date
    Oct 2001
    Posts
    598
    I'm a rookie at this however is

    int main()
    {
    cout << "Hello world";
    cout<< " Press any key to return to dos";
    getchar();
    return 0;
    }

    a stupid solution??

  8. #8
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125
    This will do the trick for this specific purpose. However, if you ran it from a regular DOS window, it will cause you to press a key to exit it whereas it should have executed normally. After me having said this I only want to add that the implementation is always up to the programmer himself to be decided.

    Cheers.
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MS DOS Window closes right away!
    By poolshark1691 in forum C++ Programming
    Replies: 5
    Last Post: 05-24-2005, 11:35 AM
  2. File systems?? (Winxp -> DOS)
    By Shadow in forum Tech Board
    Replies: 4
    Last Post: 01-06-2003, 09:08 PM
  3. Dos Window closes after I press enter
    By ProgrammingDlux in forum C++ Programming
    Replies: 4
    Last Post: 01-24-2002, 12:13 PM
  4. dos closes right away after executing
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 01-18-2002, 03:59 AM
  5. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 01:42 PM