[英]If I'm trying to create a Queue in C++, how do I make the Queue of a certain size?
[英]How do I make this work? I'm not good in C++
#include <iostream>
using namespace std;
int main() {
char username[50];
char password[50];
char passConfirm[50];
cout << "Create a username: ";
cin >> username;
cout << "Create a password: ";
cin >> password;
cout << "Confirm your password: ";
cin >> passConfirm;
if (password == passConfirm) {
cout << "Password confirmed";
} else {
cout << "Password denied";
}
}
試圖查看用戶輸入是否與另一個用戶輸入相同,但我不知道該怎么做。
我嘗試這樣做是為了查找密碼是否與 passConfirm 相同,但它不起作用,我不知道該怎么做。
char[]
是 C 處理字符串的方法。 如果你要那樣做,你需要strcmp
來比較它們。
#include <cstring>
...
if (std::strcmp(password, passConfirm) == 0) { ... }
但更好、對 C++ 更友好的方法是使用std::string
。
#include <string>
...
std::string password;
std::string passConfirm;
然后==
比較將按您預期的那樣工作。
#include <iostream>
using namespace std;
int main() {
string username;
string password;
string passConfirm;
cout << "Create a username: ";
cin >> username;
cout << "Create a password: ";
cin >> password;
cout << "Confirm your password: ";
cin >> passConfirm;
if (password == passConfirm) {
cout << "Password confirmed";
} else {
cout << "Password denied";
}
}
字符串是一個字符向量,因此沒有必要創建一個字符數組
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.