Thread: problem with pausing the program

  1. #1
    Registered User
    Join Date
    Oct 2003

    problem with pausing the program

    I am having a problem porting some windows code to Linux and having that "press any key to continue" thingee, I have tried every scrap of code in your FAQ regarding this issue, and they all work in their own programs, when I try to add it to my code though, it doesn't work, I have tried both Xterm and the console with same results.
    std::cout << "\n		Enter Choice: ";
    		std::cin >> choice;
              case 'i':
                   system ("clear");
                   std::cout << "\n\n\n\n\n\n\n            Program has been set to defaults.";
               //    std::cout << "\n                     Press any key to continue." <<std::endl;
                 //       getch();
    The getch() above is using the termios method from your FAQ, I have tried all portable methods, and nothing works. Any help would be great!

  2. #2
    Registered User subdene's Avatar
    Join Date
    Jan 2002

    Wait till i get the c++ standard people on my backs.
    Be a leader and not a follower.

  3. #3
    Registered User
    Join Date
    Jun 2003
    If you are using/porting to Linux, you may want to look at NCurses.

    getchar() ? Eughh.. Please, this is a C++ forum!

  4. #4
    Registered User
    Join Date
    Oct 2003
    I think I may do this differently, by making a sleep function........although, the getch() function works great in windows, compiler specific however, we need a standard <conio.h>

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Post a small and complete program which shows the problem.

    My guess is that you're suffering from trailing characters left by cin >> choice (just like scanf() does in C programs), and your attempt to wait for a key "doesn't work".

    cin.ignore(1000,'\n'); // skip at most 1000 chars looking for a newline
    just before you want to wait for a key.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem w/ doubles in friend's program
    By mkylman in forum C Programming
    Replies: 16
    Last Post: 11-22-2008, 10:45 AM
  2. I have finished my program, one problem
    By sloopy in forum C Programming
    Replies: 4
    Last Post: 11-29-2005, 02:10 AM
  3. Program problem
    By Birdhaus in forum C++ Programming
    Replies: 6
    Last Post: 11-21-2005, 10:37 PM
  4. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM