用“替换输入"* "C++ [英] Replace input with " * " C++

查看:16
本文介绍了用“替换输入"* "C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户输入密码.当然这是一个秘密密码,所以没有人应该看到它.所以我试图用'*'替换用户输入的字母和数字.这是我的尝试.

i want the user to input a passwort. of course it's a secret passwort so nobody should see it. so i tried to replace the letters and numbers the user inputs, with ' * '. here is my try.

while ((pw=getch())!='x'){
cout << "*";
strcpy(pwstring,pw);

}

input_pw=atoi(pwstring.c_str());

稍后我希望x"成为输入".但目前这并不重要.有了这个,我在 Visual Studio 下得到了一些编译器错误.

later i want the 'x' to be a 'enter'. but at the moment it's not important. with this, i get some compiler errors under Visual Studio.

Fehler  3   
error C2664: 'strcpy': Konvertierung des Parameters 1 von 'char' in 'char *' nicht möglich  c:users	imdesktopkalssnnemethoden.h    zeile: 70

我会试着翻译一下.

error 3
error C2664: 'strcpy': converting of parameter 1 from 'char' to 'char*' is not possible.



  official english error code
    "'function' : cannot convert parameter number from 'type1' to 'type2'" 

thank u:  R. Martinho Fernandes

但这意味着什么,我该如何解决?

but what does this mean, and how can i fix it?

希望你能帮助我

问候.

推荐答案

你的问题不是关于 C++,而是关于如何与你的终端交互.该语言(故意)完全不知道如何处理输入和输出,而您所担心的一切都是终端的行为方式.因此,任何答案都将在很大程度上取决于您的平台和终端.

Your question isn't as much about C++ as it is about how to interact with your terminal. The language is (deliberately) entirely agnostic of how input and output are handled, and everything that you're worried about is how the terminal behaves. As such, any answer will depend heavily on your platform and your terminal.

在 Linux 中,您可能需要查看 termios.hncurses.h.有一个旧的 Posix 函数 getpass() 可以执行与您想要的类似的操作,但已被弃用.

In Linux, you will probably want to look into termios.h or ncurses.h. There's an old Posix function getpass() which does something similar to what you want, but it's deprecated.

不幸的是,我不知道如何在 Windows 中进行终端编程.

Unfortunately I have no idea how to approach terminal programming in Windows.

这篇关于用“替换输入"* &quot;C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆