C++21点课程设计,设置密码

在屏幕输入时密码用*号代替
密码为123时为高级玩家
321时为超级玩家

 #include <conio.h>
#include <iostream>
using namespace std;
int main() {
    char* password;

    int length = 3;
    password = new char[length + 1];

    char* p = NULL;
    int count = 0;

    cout << "Input password : ";
    p = password;
    count = 0;
    //fflush(stdin);
    while (((*p = getch()) != 13) && count < length) {
        // 这里不是'\n'(10), new line
        // 而是'\r'(13), reback. 即是按下回车键,好像这个东西是linux的.
        // 主要是与getch这个函数有关.
        putch('*');
        fflush(stdin);

        p++;
        count++;
    }
    password[count] = '\0';

    cout << endl;
    if (strcmp(password, "123") == 0)
    {
        cout << "高级玩家" << endl;
    }
    else if (strcmp(password, "321") == 0)
    {
        cout << "超级玩家" << endl;
    }
    else
    {
        cout << "普通玩家" << endl;
    }

    delete []password;
    password = NULL;

    system("pause");
    return 0;
}
 #include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#define  LEN 12

int _tmain(int argc, _TCHAR* argv[])
{
    printf("please enter a password\n");
    char password[LEN+1];
    memset(password,NULL,LEN+1);
    int i=0;
    char ch;
    ch=getch();
    while(isprint(ch) && ch!=' '){
    password[i]=ch;
    i++;
    if(i==LEN)
    break;
    putchar('*');
    ch=getch();
    }
    if (strcmp(password, "123") == 0)
        printf("\nyou are advanced gamer.");
    else if (strcmp(password, "321") == 0)
        printf("\nyou are super gamer.");
    else
        printf("\nyour password is %s", password);
    printf("\n", password);
    return 0;
}

图片说明
运行效果。

VC ?
星号代替,你可以找你文本框的属性,设置成密码
至于密码是123 321 就在你button中判断一下就可以了

获得密码后判断就行了

图片说明

再来一个windows版本的

采纳留下邮箱可以把代码给你。