Thread: _getche() is not portable...

  1. #1
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246

    Question _getche() is not portable...

    What should I use instead of _putche() in my codes. There is really no replacement for this?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    _putche is from what library?

    If there is no standard alternative, then you just have to use non-standard code. In your release of the source, you'll have to say what libraries you used. It's not uncommon and it's not that bad. There is no real standard APIs and no standard conio functions, but people use them when they're necessary.

    If, by chance, you know how to replicate it using standard library functions, then you could try to do that. It will make it much easier, as you can distribute it with your release.
    Sent from my iPadŽ

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    _putche is from what library?
    [edit]
    I mean _getche() [edit] and it gives you a warning if you use getche().
    Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getche. See online help for details.'
    Isn't it strange that C/C++ doesn't have a standard function for reading one key from keyboard buffer? Now I have to use getche().
    Last edited by siavoshkc; 08-13-2006 at 05:29 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    It's not so strange when you think about the reason why C++ doesn't have a standard function for reading from the keyboard buffer. The problem is that concepts such as keyboard buffers are entirely system specific, so there is no way that the C++ standard could possibly cater for it. much in the same way that C++ doesn't cater for mouse input or graphical functions.

    using non-standard and non-portable code isn't a bad thing, in fact, it's usually not possible, or desirable, to stick 100% to the standard C++ language for any (useful) real-world application, just that, as a user of the libraries, you'll usually find far less support around than for the standard language (Except perhaps Boost and some MS libraries), hence why beginners are generally discouraged from diving into them before being comfortable with the language first
    Last edited by Bench82; 08-13-2006 at 06:15 PM.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I'm not sure if we are talking about _putche() or _getche() here.

    _getche() is Visual C++ 2005 replacement for getche().

    _putche() doesn't exist anywhere in MSDN documentation. There exists _putch() which is the replacement function for putch(). But no _putche(). Since the difference between _getch and _getche is simply the fact the character will be or not echoed to the screen, I can't seem to find a reason for a _puthche() function. What would be the purpose of writting a character to the console without echoing it?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    http://msdn2.microsoft.com/en-us/library/azb6c04e.aspx

    These functions write the character c directly, without buffering, to the console.
    Referring to _putch and _putwch

    You can define getch to _getch[e] if you are on a non-POSIX (Windows) system and have conio, or otherwise have curses. Or use something like pdcurses.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    There's putchar() and getchar(), which work with stdout and stdin respectively. They do what you say "reading [or write] one key from keyboard buffer".

    Edit: But if your using c++ it's better to do "cin >> mychar" and "cout << mychar".

    _getch(), _getche() and _putch() are unbuffered.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  8. #8
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    _putche() doesn't exist anywhere in MSDN documentation.
    It exists only in this thread, it is my typing mistake. I mixed getche() and putch() together!!!
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-14-2009, 02:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  3. Replies: 3
    Last Post: 09-01-2005, 11:47 AM
  4. which Portable mp3 player?
    By Raihana in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 01-09-2004, 07:58 AM
  5. Portable nonbusy hold?
    By Imperito in forum C Programming
    Replies: 2
    Last Post: 09-06-2002, 11:48 AM