c++

c++ getch怎样不显示字符

小樊
90
2024-07-21 14:33:59
栏目: 编程语言

您可以使用以下代码来实现在C++中不显示字符输入的功能:

#include <iostream>
#include <conio.h>

int main() {
    char ch;
    
    std::cout << "Enter a character: ";
    
    // Hide the character input
    ch = _getch();
    
    // Do something with the character input
    std::cout << "\nYou entered: " << ch << std::endl;
    
    return 0;
}

在这个示例中,我们使用_getch()函数从用户获取字符输入,但是由于该函数不会将字符显示在控制台上,因此用户输入的字符将不会在屏幕上显示。

0
看了该问题的人还看了