我想創建一個允許用戶創建密碼和用戶名的程序。但是,密碼必須介於6到10個字符之間。我將如何限制字符輸入?另外,如果我想要密碼包含大寫字母呢?C++ - 限制字符串長度
下面就一起來看看該計劃到目前爲止給你什麼,我試圖做一個想法(注:我知道這個程序本身顯然沒有完成,但我只是想給你一個視覺):
#include <iostream>
#include <string>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "--------------------------------------------------------------\n";
std::cout << " Welcome to the ECE!! Password Proram!\n";
std::cout << "Username rules: must be 5-10 characters long with no space\n";
std::cout << "Password rules: must be 6+ characters long\n";
std::cout << "Must contain one uppercase letter and one number but no space\n";
std::cout << "--------------------------------------------------------------\n";
//Let's get our password!
std::string username;
std::string password;
const int
//use a do while loop for input validation
do {
std::cout << "Enter your username: ";
std::cin >> username; //add input validation
} while();
std::cout << "Enter your password:";
std::cin >> password;
return 0;
}
閱讀說明書! – HazemGomaa