DOS app question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Huntwork

    DOS app question

    Hello,

    I am new to C++ and am taking my first class and in my programs I
    would like to add a non-required feature.

    I would like for my app to not close immediately after completion in
    Windows when starting it via the ol' double click.

    I know that if I start it from a DOS prompt everything will work out
    just fine but I and several others would like to "improve" our
    projects.

    Any suggestions?

    Thanks,

    Mike
  • Attila Feher

    #2
    Re: [OT] DOS app question

    Michael Huntwork wrote:[color=blue]
    > Hello,
    >
    > I am new to C++ and am taking my first class and in my programs I
    > would like to add a non-required feature.
    >
    > I would like for my app to not close immediately after completion in
    > Windows when starting it via the ol' double click.
    >
    > I know that if I start it from a DOS prompt everything will work out
    > just fine but I and several others would like to "improve" our
    > projects.
    >
    > Any suggestions?[/color]

    OFF-TOPIC

    Read in a string at the end of your code. Or (since it seems to be for
    Windows only) include <stdlib.h> (not stdlib, which would be C++, MS
    compilers had problems with putting everything to std namespace) and call
    system("pause") ; at the end of your program. (This is a non-portable little
    hack!)

    Please note, that your question has nothing to do with the C++ language!
    Before you post here again, please read this:


    --
    Attila aka WW


    Comment

    • Sumit Rajan

      #3
      Re: DOS app question

      Michael Huntwork wrote:

      [color=blue]
      > I am new to C++ and am taking my first class and in my programs I
      > would like to add a non-required feature.
      >
      > I would like for my app to not close immediately after completion in
      > Windows when starting it via the ol' double click.
      >
      > I know that if I start it from a DOS prompt everything will work out
      > just fine but I and several others would like to "improve" our
      > projects.[/color]

      Add "system("pause" );" at the point you require your program to display a
      "Press any key to continue ... " sort of prompt.

      HTH,
      Sumit.

      Comment

      • Sumit Rajan

        #4
        Re: DOS app question

        Sumit Rajan wrote:
        [color=blue]
        > Michael Huntwork wrote:
        >
        >[color=green]
        >> I am new to C++ and am taking my first class and in my programs I
        >> would like to add a non-required feature.
        >>
        >> I would like for my app to not close immediately after completion in
        >> Windows when starting it via the ol' double click.
        >>
        >> I know that if I start it from a DOS prompt everything will work out
        >> just fine but I and several others would like to "improve" our
        >> projects.[/color]
        >
        > Add "system("pause" );" at the point you require your program to display a
        > "Press any key to continue ... " sort of prompt.[/color]


        Remember that this is not a very portable way of doing this since "pause" is
        a DOS command which displays something to the effect of "Press any key to
        continue ... ". Using pause will not work on Linux, etc.

        Sumit.


        Comment

        • Mike Wahler

          #5
          Re: DOS app question


          Michael Huntwork <huntwork@msu.e du> wrote in message
          news:2585dbb.03 09071817.7a2a68 29@posting.goog le.com...[color=blue]
          > Hello,
          >
          > I am new to C++ and am taking my first class and in my programs I
          > would like to add a non-required feature.
          >
          > I would like for my app to not close immediately after completion in
          > Windows when starting it via the ol' double click.
          >
          > I know that if I start it from a DOS prompt everything will work out
          > just fine but I and several others would like to "improve" our
          > projects.
          >
          > Any suggestions?
          >[/color]

          #include <iostream>

          int main()
          {

          /* your code */

          std::cout << "Press return to continue";
          std::cin.get();
          return 0;
          }

          -Mike



          Comment

          • Mike Wahler

            #6
            Re: DOS app question


            Sumit Rajan <sumitrajan@myr ealbox.com> wrote in message
            news:3f5bf7a9@s hknews01...[color=blue]
            > Michael Huntwork wrote:
            >
            >[color=green]
            > > I am new to C++ and am taking my first class and in my programs I
            > > would like to add a non-required feature.
            > >
            > > I would like for my app to not close immediately after completion in
            > > Windows when starting it via the ol' double click.
            > >
            > > I know that if I start it from a DOS prompt everything will work out
            > > just fine but I and several others would like to "improve" our
            > > projects.[/color]
            >
            > Add "system("pause" );" at the point you require your program to display a
            > "Press any key to continue ... " sort of prompt.[/color]

            This will only work for platforms which have such a 'pause'
            command, and that it does what the OP asks. I.e. it's a non-
            portable solution. See my post this thread for a portable
            solution.

            -Mike



            Comment

            Working...