用“替换输入"* "C++

Replace input with quot; * quot; C++(用“替换输入* quot;C++)
本文介绍了用“替换输入"* "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++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)