problem with pausing the program

This is a discussion on problem with pausing the program within the C++ Programming forums, part of the General Programming Boards category; I am having a problem porting some windows code to Linux and having that "press any key to continue" thingee, ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    12

    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.
    Code:
    .
    .
    .
    std::cout << "\n		Enter Choice: ";
    
    		std::cin >> choice;
    
    
    
         switch(choice)
         {
              case 'i':
                   system ("clear");
                   one.ClearIt();
                   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();
                  
              break;
    .
    .
    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
    Posts
    359
    getchar();

    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
    Posts
    245
    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
    Posts
    12
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    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".

    Try
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 09:45 AM
  2. I have finished my program, one problem
    By sloopy in forum C Programming
    Replies: 4
    Last Post: 11-29-2005, 01:10 AM
  3. Program problem
    By Birdhaus in forum C++ Programming
    Replies: 6
    Last Post: 11-21-2005, 09:37 PM
  4. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21