c++做有光标的登录界面
时间: 2024-02-23 12:58:14 浏览: 23
可以使用C++中的控制台窗口来创建一个有光标的登录界面。以下是一个简单的示例代码:
```c++
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int main()
{
string username, password;
cout << "Enter username: ";
cin >> username;
cout << "Enter password: ";
char ch;
while ((ch = _getch()) != '\r') {
password.push_back(ch);
cout << "*";
}
// do something with the username and password
return 0;
}
```
在控制台窗口中,可以使用`cout`和`cin`来获取用户输入的用户名和密码。为了使密码输入时不显示明文,可以使用`_getch()`函数来实现。在输入密码时,每输入一个字符就输出一个星号来代替实际字符。最后,可以将输入的用户名和密码用于后续的操作。
相关问题
做一个简c++登陆含光标
好的,下面是一个简单的 C++ 登录程序,含光标:
```c++
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main() {
string username, password;
cout << "请输入用户名:";
cin >> username;
cout << "请输入密码:";
char ch = _getch();
while (ch != '\r') {
password.push_back(ch);
cout << "*";
ch = _getch();
}
cout << endl;
if (username == "admin" && password == "123456") {
cout << "登录成功!" << endl;
} else {
cout << "用户名或密码错误!" << endl;
}
return 0;
}
```
该程序会要求用户输入用户名和密码,并判断输入是否正确。密码输入时,会将输入的字符替换为“*”,以保护密码的安全。如果用户名和密码都是正确的,则输出“登录成功!”;否则输出“用户名或密码错误!”。
用c++写一个登陆界面
好的,以下是一个简单的用 C 语言编写的登陆界面:
#include <stdio.h>
#include <string.h>
int main() {
char username[20];
char password[20];
printf("请输入用户名:");
scanf("%s", username);
printf("请输入密码:");
scanf("%s", password);
if (strcmp(username, "admin") == 0 && strcmp(password, "123456") == 0) {
printf("登陆成功!\n");
} else {
printf("用户名或密码错误!\n");
}
return 0;
}
希望这个代码能够帮到你!