Standard input without echo

30 views
Skip to first unread message

Raymart Atienza

unread,
Jul 29, 2015, 2:54:08 AM7/29/15
to ISO C++ Standard - Discussion
Hi all,

I'd like to know if it is possible for the standard input stream to accept input from the console and not echo it on screen? Thanks.
What are your thoughts on this matter? I think this is useful when we are processing sensitive input from the console screen.
I know that this is possible using _getch() function from Microsoft, but this is not portable and only works in Windows. Is there a C++ way of doing this?

David Krauss

unread,
Jul 29, 2015, 3:10:15 AM7/29/15
to std-dis...@isocpp.org
On 2015–07–29, at 2:54 PM, Raymart Atienza <monsterbots...@gmail.com> wrote:

Hi all,

I'd like to know if it is possible for the standard input stream to accept input from the console and not echo it on screen? Thanks.

Yes: adjust the console.

The C++ standard library, or indeed any part of the program, is not generating the echo.

What are your thoughts on this matter? I think this is useful when we are processing sensitive input from the console screen.
I know that this is possible using _getch() function from Microsoft, but this is not portable and only works in Windows. Is there a C++ way of doing this?

man getch tells me that it’s part of the curses/ncurses library, which can communicate with the OS or terminal program to disable the echo.

I’m not sure of the standardization status of that library. It appears to have been part of POSIX SUSv2 but I can’t find it in newer editions. Anyway, it’s not Windows-only, but it’s somewhat less likely to be standardized than other parts of POSIX.

Edward Catmur

unread,
Jul 29, 2015, 7:43:08 AM7/29/15
to ISO C++ Standard - Discussion, pot...@gmail.com
On Wednesday, 29 July 2015 08:10:15 UTC+1, David Krauss wrote:
I’m not sure of the standardization status of that library. It appears to have been part of POSIX SUSv2 but I can’t find it in newer editions. Anyway, it’s not Windows-only, but it’s somewhat less likely to be standardized than other parts of POSIX.

X/Open Curses (XCURSES) is an X/Open Technical Specification; it is part of the Single UNIX(R) Specification as of SUSv4 (2013) but not part of POSIX (as of ISO/IEC 9945:2009/Cor 1:2013(E). (That is, SUSv4 is POSIX 2013 plus XCURSES 7).

Any SUS compliant platform will offer at least one XCURSES compliant library but methods of accessing it (e.g. compiler/linker flags) may vary; your build system should be able to help you there.

An alternative to getch is the lower-level termios function tcsetattr (c_lflag &= ~ECHO), which is specified by POSIX.
Reply all
Reply to author
Forward
0 new messages