如何使终端请求字符串,然后在接收到字符串后删除它



嗨,我正在制作一个迷你银行,我想让用户输入电子邮件,然后一旦他们输入,它就会清除,然后移动到密码,我在做这件事时遇到了麻烦,请帮助。

#include <iostream> 
#include <windows.h>
#include <String>
#include <thread>
#include <stdlib.h>
int main() {
int money = 1000000;
std::string password;
std::string email;
std::string Inpassword;
std::string Inemail;
std::cout << ("Welcome to the bank of jack!n");
Sleep(2000);
std::cout << ("Enter your email:  ");
std::cin >> email;
//the user enters the email and then once the user inputs the email the computer clears the text containing the email 
Sleep(3000);
std::cout << ("create your password: ");
std::cin >> password;
//user inputs password and then once its pasted the computer clears it 
Sleep(1000); 
std::cout << ("Account createdn");
Sleep(1000);
//after that the entire terminal is cleared
std::cout << ("Log inn");
Sleep(1000);
std::cout << ("enter your emailn");
std::cin >> Inemail;
if (Inemail == email) {
std::cout << ("user ") << email << (" located");
}
else {
std::cout << ("incorrect email");
exit(0);
}
}

您是否尝试过在请求密码之前使用cstdlib的系统功能执行cls命令清空控制台?

使用例子:

system("cls");

所以将Your Code修改如下,在输入邮箱和密码后清空终端。

#include <iostream> 
#include <windows.h>
#include <String>
#include <thread>
#include <cstdlib>
int main() {
int money = 1000000;
std::string password;
std::string email;
std::string Inpassword;
std::string Inemail;
std::cout << ("Welcome to the bank of jack!n");
Sleep(2000);
std::cout << ("Enter your email:  ");
std::cin >> email;
//the user enters the email and then once the user inputs the email the computer clears the text containing the email 
Sleep(3000);
system("cls");
std::cout << ("create your password: ");
std::cin >> password;
//user inputs password and then once its pasted the computer clears it 
Sleep(1000); 
system("cls");
std::cout << ("Account createdn");
Sleep(1000);
//after that the entire terminal is cleared
system("cls");
std::cout << ("Log inn");
Sleep(1000);
std::cout << ("enter your emailn");
std::cin >> Inemail;
if (Inemail == email) {
std::cout << ("user ") << email << (" located");
}
else {
std::cout << ("incorrect email");
exit(0);
}

如果是Linux/Mac环境,请确保将cls命令替换为clear。希望这对你有帮助

最新更新