-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanother_func.cpp
More file actions
49 lines (43 loc) · 1.24 KB
/
another_func.cpp
File metadata and controls
49 lines (43 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "basis.h"
void secgetpasseord(std::string& password)
{
char passwordarray[20];
char ch;
int i = 0;
cout<<"enter your password "<<endl;
while (true)
{
ch = (char)getch(); // 获取键盘输入的字符,但不显示在屏幕上
if (ch == '\r') {
passwordarray[i] = '\0'; // 将字符串结束符加入密码字符串
break; // 输入结束,退出循环
}
else if (ch == '\b')
{
if (i > 0)
{
i--;
printf("\b \b"); // 退格操作,删除上一个字符并移动光标位置
}
}
else
{
passwordarray[i] = ch; // 将字符存入密码字符串
i++;
printf("*"); // 显示*代替输入的字符
}
}
//printf("\npassarray: %s\n", passwordarray);//测试链接
std::string cppstrchange(passwordarray);
password = cppstrchange;
}
bool startsWith(const std::string& str, const std::string& prefix)
{
// 比较前缀长度和字符串长度
if (str.size() < prefix.size())
{
return false;
}
// 使用 compare 函数进行前缀比较
return str.compare(0, prefix.size(), prefix) == 0;
}