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

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

问题描述

我想让使用者输入通行证。当然是一个秘密的passwort所以没有人应该看到它。
所以我试图替换用户输入的字母和数字,用'*'。这是我的尝试。

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

}

input_pw = atoi(pwstring.c_str());

稍后我想要将'x'作为'enter'。但目前它并不重要。这样,我在Visual Studio下得到一些编译器错误。

  Fehler 3 
错误C2664:'strcpy':Konvertierung des参数1 von'char'in'char *'nichtmöglichc:\users\tim\desktop\kalssnne\methoden.h zeile:70

我会尝试翻译这个。

 错误3 
error C2664:'strcpy':将参数1从'char'转换为'char *'是不可能的。



官方英语错误代码
'function':无法将参数号从'type1'转换为'type2'

谢谢u:R. Martinho Fernandes

但是这是什么意思, / p>

希望您可以帮助我



问候。

解决方案

您的问题不是关于C ++,而是关于如何与您的终端进行交互。语言(故意)完全不知道如何处理输入和输出,并且你担心的一切都是终端如何行为。因此,任何答案都将严重依赖于您的平台和终端。



在Linux中,您可能想查看 termios.h ncurses.h 。有一个旧的Posix函数 getpass()它类似于你想要的东西,但已被弃用。



我不知道如何接近Windows中的终端编程。


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());

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\tim\desktop\kalssnne\methoden.h    zeile: 70

i will try to translate this.

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?

hope u can help me

greetings.

解决方案

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.

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.

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

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

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