Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;密码保护错误,我需要帮助:D_C++_String_Passwords_Cout_Cin - Fatal编程技术网

C++ C++;密码保护错误,我需要帮助:D

C++ C++;密码保护错误,我需要帮助:D,c++,string,passwords,cout,cin,C++,String,Passwords,Cout,Cin,我想知道是否有任何代码使您键入的内容(例如,Hello变成***)变得不可解码 我有这个密码 string pass; 当你输入“cin”时,我不想让任何人都能读懂它 cin >> pass; cout << pass; cin>>通行证; cout这里我们用星号屏蔽输入。我们使用tcgetattr/tcsetattr来获取和设置终端属性,以便在stdin上禁用echo,并在每个字符用户输入上打印“*” #include <iostream> #inclu

我想知道是否有任何代码使您键入的内容(例如,
Hello
变成
***
)变得不可解码

我有这个密码

string pass;
当你输入“cin”时,我不想让任何人都能读懂它

cin >> pass;
cout << pass;
cin>>通行证;

cout这里我们用星号屏蔽输入。我们使用
tcgetattr
/
tcsetattr
来获取和设置终端属性,以便在stdin上禁用echo,并在每个字符用户输入上打印
“*”

#include <iostream>
#include <string>
#include <termios.h>
#include <stdio.h>

int getch() {
    struct termios oldtc, newtc;
    int ch;
    tcgetattr(STDIN_FILENO, &oldtc);
    newtc = oldtc;
    newtc.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newtc);
    ch=getchar();
    tcsetattr(STDIN_FILENO, TCSANOW, &oldtc);
    return ch;
}


int main(int argc, char **argv) {

    int ch;
    printf("Press ENTER to exit.\n\n");

    for (;;) {

        ch = getch();

        if(ch == '\n')
              break;
        printf("*");
    }

    return 0;
}
#包括
#包括
#包括
#包括
int getch(){
结构termios oldtc、newtc;
int-ch;
tcgetattr(标准文件号和旧TC);
newtc=oldtc;
newtc.c|lflag&=~(ICANON | ECHO);
tcsetattr(标准文件号、TCSANOW和newtc);
ch=getchar();
tcsetattr(标准文件号、TCSANOW和oldtc);
返回ch;
}
int main(int argc,字符**argv){
int-ch;
printf(“按ENTER键退出。\n\n”);
对于(;;){
ch=getch();
如果(ch='\n')
打破
printf(“*”);
}
返回0;
}

以下代码已在Visual Studio 2012(也是VC6.0)上测试并可运行。有关函数_getch()的更多信息,请访问

_getch():从控制台获取不带echo(\u getch)或带echo(\u getche)的字符

#包括
#包括
#包括
int main()
{
std::字符串传递;
for(int c;c=_getch();){
如果(c='\r'| c='\n'| c==EOF){
打破
}否则{
通过+=c;

STD::不在标准C++的范围内。也许你的操作系统提供了一个直接控制文本I/O的库。创建一个函数,它计算字符的数量,为每个字符加一个A*,然后返回密码编码的文本。你可以检查这些@ RyNOH97。我不知道如何做:/完全隐藏输入可能是完整的。E
#include <iostream>
#include <string>
#include <conio.h>

int main()
{
    std::string pass;
    for(int c; c = _getch(); ){
        if(c=='\r' || c=='\n' || c==EOF){
            break;
        }else{
            pass += c;
            std::cout << '*';
        }
    }

    std::cout << "\nYour password is: " << pass << std::endl;
    return 0;
}