getch()

This is a discussion on getch() within the C++ Programming forums, part of the General Programming Boards category; Under Windows, when we want to do the "Hit any key to continue...", we can just enter the getch() function ...

  1. #1
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164

    getch()

    Under Windows, when we want to do the "Hit any key to continue...", we can just enter the getch() function from the conio.h library.

    Obviously this is not portable to unix. (is it curses.h we need for unix???)

    Is there a way to make this portable across all platforms??

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    How many times does a FAQ have to say there is no portable solution before you accept it and move on?
    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.

  3. #3
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    I remember seeing something similar a while ago where somone was using something like (excuse my attempt)

    #define __linux__
    #define __windows__

    #if defined __linux__

    etc...

    would it not be possible to use something like this, or some other way of checking the OS, and instructing the compiler to choose the correct code???

    Just a thought.

  4. #4
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    That is only at compile time. At run time, it will only allow the system it was run on (if it uses non-portable code).
    Do not make direct eye contact with me.

  5. #5
    Registered User
    Join Date
    Jan 2004
    Posts
    25
    Just use this:

    system("pause");
    My work:
    http://phil.webula.net

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ^ since when did 'pause' work on Linux?

    you could just try using cin.get() in place of getch()...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Originally posted by Lurker
    That is only at compile time. At run time, it will only allow the system it was run on (if it uses non-portable code).
    Even if it uses fully portable code, it will still only run on the type of system it was compiled on. A program compiled to run on windows will not run on linux anyway, regardless of how portable the code is.

    So compile-time decisions like that will work.
    Last edited by nickname_changed; 01-08-2004 at 05:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 04:15 AM
  3. Pause a C program without getch()
    By swgh in forum C Programming
    Replies: 4
    Last Post: 02-20-2006, 10:24 AM
  4. Clearing input buffer after using getch()
    By milkydoo in forum C++ Programming
    Replies: 3
    Last Post: 07-21-2003, 11:04 PM
  5. Problems with getch()
    By GrNxxDaY in forum C++ Programming
    Replies: 14
    Last Post: 08-12-2002, 02:11 AM

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