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'm explaining that cin.get() is not a suitable replacement for getch() for the applications given above.įor the application I mentioned it's a perfectly suitable replacement. That was already mentioned, so you don't have to list the compilers where it does and doesn't work. 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. Okay, point out on this thread where you're not the first person to mention a specific compiler or OS. >The MinGW compiler supports getch, so anyone using a It's generally considered rude to resurrect ancient threads, for any reason. >i just thought I'd post it here for anyone who stumbles across it as I did. 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 believe that the ".h" version was the one used before streams became standard (in Borland). What compilers don't support it?ģ) I'm explaining that cin.get() is not a suitable replacement for getch() for the applications given above.Ĥ) Okay, you got me there. And MS Visual C++ also has the conio library. After it's been compiled, running the program on the intended platform should have the expected results.Īlso, as Cygwin installations typically include MinGW libraries, Cygwin also supports the conio functions like getch. The MinGW compiler supports getch, so anyone using a MinGW compiler will be able to compile the code. i just thought I'd post it here for anyone who stumbles across it as I did.Ģ) It's not that hard for me to understand, and that's why I added the condition "in MinGW". I do make mistakes, but I get the strong impression that you're not a strong enough programmer to notice them or accurately correct me even if you do.ġ) Yes, I realize that. Narue is always right when it comes to the likes of you. Once again, this is a very simple concept, but I'll assume that you're just having trouble with reading for comprehension and missed the ".h" part. You'd do well to realize that before truly embarrassing yourself. However, I'll give this to you because I can't think of any systems off the top of my head that don't buffer up to a line feed.
getchar makes a call to a system function that performs the actual read, and that system function (whatever it may be) isn't required by the C++ standard to provide cooked input. >pressed key and waits for enter to be pressed.Īssuming that's what getchar does.
>cin.get() acts the same as getchar() - it echos the Is this that difficult of a concept for you people to grasp? 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. >getch() is still available in the conio.h header file (at least in MinGW). You realize the thread is over three years old, yes? That said, any nonstandard function has the implied disclaimer, "use at your own risk"! :p I do try to get them to go the right way first, otherwise it seems to be a much longer journey.
Frankly, if the command shell commands behaved this way, I'd be pretty annoyed: execute two 'dir' commands consecutively, and the second throws away the result of the first - annoying.Īh well, it seems new programmers always must go full circle. Their first goal seems to be clearing the screen. Yet this opinion is revisited thousands of times every year by programmers. It seems a more reasonable approach is to use standard functions that have already taken such issues into account and move forward. The reason it may 'work well' might be because other issues have been overlooked. Then you're back where you started with the standard way. Then you can't have immediate response because you need an "enter" for a 'final' answer. Do you allow the user to make a typing mistake? Then handle the backspace. The problem with unbuffered input is that it becomes the responsibility of the programmer to handle the buffering. I would really love to know if there's any other way to get the functionality of getch()(i.e without using getch()) in the above mentioned cases.