Cin Masking

This is a discussion on Cin Masking within the C++ Programming forums, part of the General Programming Boards category; Hi
Is it possible to mask input gained using cin so that when a user type a different character (e.g. ...

If I understand you correctly, as the user types input, you want a character they type to appear as a * rather than the key they actually typed. As far as I know, a C++ console program doesn't know what the user has done until they hit return. However, in other languages like javascript, you can detect keypresses and change their output, so I would think there would be something similar if your program was a windows program.

The answer is yes and no It really depends on your OS and your compiler. What you have to do is to take it out of "cooked" mode and put it into "raw" mode. You can not do this with cin. But it can be done with the buffer cin points to. What you are looking to do can be accomplished with getch() if your OS/Compiler supports it.

The basic thing is the user has to enter a "passcode" of 4 numbers which are stored in an integer when the user presses enter. I want a * to appear on screen when they press the numbers rather then showing the actual numbers on the console screen. Is this possible?

Again it depends on your OS and Compiler. If your compiler has getch() then you can read one character at a time into an array. Then each time you output a '*'. However you must then take care of things like the user hitting the backspace or hitting function keys or what not. One the user hit's return you then take your character array and convert it to an integer and compare it.

cheers, I'll give that a try. I think the compiler I have has getch() so everything should be grand. About 30 more minutes work and I should be able to get some kip, 17 hours programming (with a couple of short breaks for food and banging of head against wall) isn't too bad

As was mentioned before, you're looking for raw input rather than cooked. Also try searching for non-canonical (raw) vs canonical (cooked) input. If you're programming for windows/dos it's rather easy. For *nix systems it get's a bit more complicated.