Reading a password from std::cin

后端 未结 4 1019
萌比男神i
萌比男神i 2020-11-22 04:46

I need to read a password from standard input and wanted std::cin not to echo the characters typed by the user...

How can I disable the echo from std::c

4条回答
  •  忘了有多久
    2020-11-22 05:33

    There's nothing in the standard for this.

    In unix, you could write some magic bytes depending on the terminal type.

    Use getpasswd if it's available.

    You can system() /usr/bin/stty -echo to disable echo, and /usr/bin/stty echo to enable it (again, on unix).

    This guy explains how to do it without using "stty"; I didn't try it myself.

提交回复
热议问题