program in c++ make the cmd stop without using getch()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CasTLeVaNia
    New Member
    • Mar 2013
    • 1

    program in c++ make the cmd stop without using getch()

    hi guys can any one give me a program in c++ that if i ran it the cmd window will stop without using getch statement and conio.h header file, or tell me how ? plz thank you
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Put your program in an infinite loop.

    Have the user enter a choice using whatever function you are happy with.

    If the choice means exit, then break out of the loop. Otherwise, the program just idles in the loop.

    Comment

    • povs937
      New Member
      • Jun 2009
      • 4

      #3
      try using
      Code:
      system("pause");

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        A system("pause") is the same as a getch() inthat you have to press enter to exit.

        With a loop waiting on the user for a choice, you can put the code for getting the choice on a separate thread which you can monitor from main(). After a specified wait, main() can shut down the program without needing a response from the user.

        Comment

        • povs937
          New Member
          • Jun 2009
          • 4

          #5
          But won't infinite loop just hang the program....?

          Comment

          • povs937
            New Member
            • Jun 2009
            • 4

            #6
            @CasTLeVaNia...
            Can you please elaborate your ques a little more?
            Do you want to freeze your cmd screen for a while?

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              The infinite loop lets the program stop usally based on a menu:

              while(1)
              {
              int choice = GetChoice();
              switch(choice)
              {
              case ADD:
              //call your "add logic"
              break;
              case DELETE:
              //call your "delete logic"
              break;
              case etc.....
              break;

              case EXIT:
              //call your cleanup logiv before exiting
              exit(1); //stop the program. The only exit(1) in the code
              default:
              printf("Incorre ct choice\n");

              }
              }

              Comment

              • markcoker
                New Member
                • Apr 2013
                • 3

                #8
                getline (cin,null); Is something like this what your after?

                Comment

                Working...