| | |
replacement of getch()
![]() |
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
1) Yes, I realize that. i just thought I'd post it here for anyone who stumbles across it as I did.
2) It's not that hard for me to understand, and that's why I added the condition "in MinGW". The MinGW compiler supports getch, so anyone using a MinGW compiler will be able to compile the code. After it's been compiled, running the program on the intended platform should have the expected results.
Also, as Cygwin installations typically include MinGW libraries, Cygwin also supports the conio functions like getch. And MS Visual C++ also has the conio library. What compilers don't support it?
3) I'm explaining that cin.get() is not a suitable replacement for getch() for the applications given above.
4) Okay, you got me there. I believe that the ".h" version was the one used before streams became standard (in Borland). Anyway, that's being nit-picky as it was probably just a typo, and anyone would very quickly discover that the ".h" is not needed (since that version isn't included in the installs anymore).
2) It's not that hard for me to understand, and that's why I added the condition "in MinGW". The MinGW compiler supports getch, so anyone using a MinGW compiler will be able to compile the code. After it's been compiled, running the program on the intended platform should have the expected results.
Also, as Cygwin installations typically include MinGW libraries, Cygwin also supports the conio functions like getch. And MS Visual C++ also has the conio library. What compilers don't support it?
3) I'm explaining that cin.get() is not a suitable replacement for getch() for the applications given above.
4) Okay, you got me there. I believe that the ".h" version was the one used before streams became standard (in Borland). Anyway, that's being nit-picky as it was probably just a typo, and anyone would very quickly discover that the ".h" is not needed (since that version isn't included in the installs anymore).
>i just thought I'd post it here for anyone who stumbles across it as I did.
It's generally considered rude to resurrect ancient threads, for any reason.
>The MinGW compiler supports getch, so anyone using a <blah blah>
Okay, point out on this thread where you're not the first person to mention a specific compiler or OS. I can describe situations that only work on a PDP-11, and they'd be just as completely irrelevant as you talking about MinGW on this thread. getch is non-portable. That was already mentioned, so you don't have to list the compilers where it does and doesn't work. That's what the manual is for.
>I'm explaining that cin.get() is not a suitable replacement for getch() for the applications given above.
For the application I mentioned it's a perfectly suitable replacement. For masking a password, it's not, but because the OP was okay with using getch after finding out that it's neither C nor C++, but a compiler extension, no replacement was necessary.
>I believe that the ".h" version was the one used before streams became standard
Correct.
>Anyway, that's being nit-picky as it was probably just a typo
I seriously doubt that it was a typo. A lot of newbies use compilers that take pre-standard code. The lack of namespaces and the use of void main makes it extremely likely that iostream.h was meant.
It's generally considered rude to resurrect ancient threads, for any reason.
>The MinGW compiler supports getch, so anyone using a <blah blah>
Okay, point out on this thread where you're not the first person to mention a specific compiler or OS. I can describe situations that only work on a PDP-11, and they'd be just as completely irrelevant as you talking about MinGW on this thread. getch is non-portable. That was already mentioned, so you don't have to list the compilers where it does and doesn't work. That's what the manual is for.
>I'm explaining that cin.get() is not a suitable replacement for getch() for the applications given above.
For the application I mentioned it's a perfectly suitable replacement. For masking a password, it's not, but because the OP was okay with using getch after finding out that it's neither C nor C++, but a compiler extension, no replacement was necessary.
>I believe that the ".h" version was the one used before streams became standard
Correct.
>Anyway, that's being nit-picky as it was probably just a typo
I seriously doubt that it was a typo. A lot of newbies use compilers that take pre-standard code. The lack of namespaces and the use of void main makes it extremely likely that iostream.h was meant.
I'm here to prove you wrong.
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; void main(){ cout << "hit any key"; cin.get(); // waiting for any input }
cin.get(); or std::cin.get(); if we don't using namespace
all works fine.
•
•
Join Date: Jan 2008
Posts: 1
Reputation:
Solved Threads: 0
getch() is also actually available in C++ while it's a compiler extension it might not be available with your compiler etc.
for example if you're using Microsoft VC++ 2005 or later you may find these two functions useful :
these methods are locking and thread-safe, non-locking versions of these two functions are available as _getch_nolock and _getwch_nolock !
--
Good Luck !
The dNetGuru
for example if you're using Microsoft VC++ 2005 or later you may find these two functions useful :
C++ Syntax (Toggle Plain Text)
int _getch( void ); wint_t _getwch( void );
--
Good Luck !
The dNetGuru
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
>To anyone reading this thread:
You realize the thread is over three years old, yes?
>getch() is still available in the conio.h header file (at least in MinGW).
I'm sure it works just fine on your compiler, but because it's non-standard, that means it's not guaranteed to work on my compiler, or someone else's compiler. Is this that difficult of a concept for you people to grasp?
The function you're discussing is NOT a "compiler extension". It's a library function. Crap like this is why people think that C/C++ is so difficult. There is a difference between a language feature and a library function. Jesus, learn the language, people!
The C++ Standard Library is not C++! Console I/O functions are not part of the compiler! You can use any library function with any compiler, as long as you compile the library source using your compiler.
Goddamn...No wonder there are so many idiot java programmers.
You have always the choice cause it C++
it just direct track of the keyboard using terminal for linux
just add its segment all will work fine..
like clrscr() also does not work for that is you can use the system() function and type the console command
In the program i have define it as "cls" so you can use it directly... as cls ; in the program
If you remove the #define Linux the code will include the Conio and you can use the getch() in any case ...
Just you any old program in windows can run fine now. .if you add this snippet above the code
it just direct track of the keyboard using terminal for linux
just add its segment all will work fine..
like clrscr() also does not work for that is you can use the system() function and type the console command
In the program i have define it as "cls" so you can use it directly... as cls ; in the program
If you remove the #define Linux the code will include the Conio and you can use the getch() in any case ...
Just you any old program in windows can run fine now. .if you add this snippet above the code
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; #define Linux //Remove this for running in windows #ifdef Linux #define cls system("clear") #include <termios.h> #include <unistd.h> int getch(); int getch() { struct termios oldt, newt; int ch; tcgetattr(STDIN_FILENO, &oldt); newt= oldt; newt.c_lflag &= ~(ICANON| ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); ch= getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return ch; } #else #include<conio.h> #define cls system("cls") #endif #include<stdio.h> .. .. int main() { .. .. return 0; }
>Found this thread when googling getch, and I had to respond.
I recommend you resist that temptation next time. Posers should know their limits.
>The function you're discussing is NOT a "compiler extension". It's a library function.
If you want to split hairs with terminology, it's a library extension. But whatever you call it, the result is the same: the function is not portable. Calling it a compiler extension is more productive as most beginners can't differentiate between the compiler proper and the libraries. If I say it's a library extension, that will encourage more questions like "I want to use graphics.h with <a compiler it wasn't designed for>".
>The C++ Standard Library is not C++!
That's not quite true. C++ is defined by the C++ standard, and you'll find sections on the standard library in that document. If a compiler package doesn't include the standard library, it doesn't conform to standard C++.
>You can use any library function with any compiler, as long
>as you compile the library source using your compiler.
Perhaps you should try to understand what you're talking about before being a jerk about it. The vendor-provided libraries for a compiler are already compiled. Sometimes vendors provide source code for the libraries, sometimes not. This results in two problems, which are more pronounced in non-portable functions like getch:
1) If you have the source code, chances are extremely good that it uses features, libraries, or APIs that are specific to either the compiler or the platform the compiler is targeted for. Unless you remove those non-portable parts, you can't use "any library function with any compiler, as long as you compile the library source using your compiler". You ultimately have to port the function to the compiler you want to use it with, which could involve a lot more work than simply recompiling.
2) If you don't have the source code, you only have a binary version of the library and thus have to disassemble and reverse engineer the functions you want before you can get to the point of compiling with another compiler. Of course, you still have to handle the first problem after you've done all of this grunt work.
>Goddamn...No wonder there are so many idiot java programmers.
You don't know what you're talking about. A little book knowledge, a pedantic attitude, and arrogance aren't going to hide that from people who do know what they're talking about.
The good news is that posers can become actual authorities on a subject. Keep trying, one day you might actually be able to debate intelligently with me.
I recommend you resist that temptation next time. Posers should know their limits.
>The function you're discussing is NOT a "compiler extension". It's a library function.
If you want to split hairs with terminology, it's a library extension. But whatever you call it, the result is the same: the function is not portable. Calling it a compiler extension is more productive as most beginners can't differentiate between the compiler proper and the libraries. If I say it's a library extension, that will encourage more questions like "I want to use graphics.h with <a compiler it wasn't designed for>".
>The C++ Standard Library is not C++!
That's not quite true. C++ is defined by the C++ standard, and you'll find sections on the standard library in that document. If a compiler package doesn't include the standard library, it doesn't conform to standard C++.
>You can use any library function with any compiler, as long
>as you compile the library source using your compiler.
Perhaps you should try to understand what you're talking about before being a jerk about it. The vendor-provided libraries for a compiler are already compiled. Sometimes vendors provide source code for the libraries, sometimes not. This results in two problems, which are more pronounced in non-portable functions like getch:
1) If you have the source code, chances are extremely good that it uses features, libraries, or APIs that are specific to either the compiler or the platform the compiler is targeted for. Unless you remove those non-portable parts, you can't use "any library function with any compiler, as long as you compile the library source using your compiler". You ultimately have to port the function to the compiler you want to use it with, which could involve a lot more work than simply recompiling.
2) If you don't have the source code, you only have a binary version of the library and thus have to disassemble and reverse engineer the functions you want before you can get to the point of compiling with another compiler. Of course, you still have to handle the first problem after you've done all of this grunt work.
>Goddamn...No wonder there are so many idiot java programmers.
You don't know what you're talking about. A little book knowledge, a pedantic attitude, and arrogance aren't going to hide that from people who do know what they're talking about.
The good news is that posers can become actual authorities on a subject. Keep trying, one day you might actually be able to debate intelligently with me.
I'm here to prove you wrong.
Narue: "Posers should know their limits."
You say it's rude to resurrect old threads but you're rude whenever you feel like it. One of the rules of this forum is "keep it pleasant". You are not following that rule. It's sad how a relatively simple skill like programming can go to a simpleton's head. Don't bother to respond; I won't read it.
You say it's rude to resurrect old threads but you're rude whenever you feel like it. One of the rules of this forum is "keep it pleasant". You are not following that rule. It's sad how a relatively simple skill like programming can go to a simpleton's head. Don't bother to respond; I won't read it.
>but you're rude whenever you feel like it
I'm appropriately rude. If you're rude to me, don't expect me to be nice to you.
>One of the rules of this forum is "keep it pleasant".
Not only am I quite familiar with the rules, I'm in the unique position of having the final say on their interpretation.
>You are not following that rule.
The key phrase in Keep It Pleasant is "malicious intent", which is the deciding factor in enforcing this rule. If it's determined that there's no malicious intent, even rude posts are more likely to be allowed than not. As such, I don't feel I've broken that particular rule. However, as it appears you've reported my post, I'll step aside and allow the rest of the mod team make an objective decision. Thank you, by the way, for reporting posts you feel cross the line regardless of who the author is. Nobody is exempt from following the rules.
>It's sad how a relatively simple skill like programming can go to a simpleton's head.
If you think programming is simple, you clearly haven't done much of it.
>Don't bother to respond; I won't read it.
I don't believe that for one second. If you're egotistical enough to scold me for not being nice when it has nothing to do with you, you're egotistical enough to be interested in my reply.
To be honest, I was half expecting your IP to match nomorejunkmail's.
I'm appropriately rude. If you're rude to me, don't expect me to be nice to you.
>One of the rules of this forum is "keep it pleasant".
Not only am I quite familiar with the rules, I'm in the unique position of having the final say on their interpretation.
>You are not following that rule.
The key phrase in Keep It Pleasant is "malicious intent", which is the deciding factor in enforcing this rule. If it's determined that there's no malicious intent, even rude posts are more likely to be allowed than not. As such, I don't feel I've broken that particular rule. However, as it appears you've reported my post, I'll step aside and allow the rest of the mod team make an objective decision. Thank you, by the way, for reporting posts you feel cross the line regardless of who the author is. Nobody is exempt from following the rules.
>It's sad how a relatively simple skill like programming can go to a simpleton's head.
If you think programming is simple, you clearly haven't done much of it.
>Don't bother to respond; I won't read it.
I don't believe that for one second. If you're egotistical enough to scold me for not being nice when it has nothing to do with you, you're egotistical enough to be interested in my reply.
To be honest, I was half expecting your IP to match nomorejunkmail's.
I'm here to prove you wrong.
![]() |
Other Threads in the C++ Forum
- Previous Thread: clear my array to calculate average and also a small question about rand
- Next Thread: VC++ access MySQL query problem
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






