我一直得到一个错误说无效类型int[int]数组下标



抱歉,如果我的代码是垃圾,我刚开始编程,我敢肯定有相当多的事情我做错了。也请让我知道我可以如何改善这一点。我正在尝试创建一个程序来检查用户输入的密码。现在我一直得到一个无效的类型错误。非常感谢你的帮助:)

#include <iostream>
#include <vector>
#include <cstring>
#define N 20
// Program that checks for a secure password so far
class Password
{
public:
char UserPassword[N];
int MenuChoice;
int Length;
int LowerCaseAmount = 0;
int UpperCaseAmount = 0;
int DigitAmount = 0;
int SpecialCharAmount = 0;
void Menu()
{
std::cout << "1. Check my current password n"
<< "2. Generate me a secure password n"
<< std::endl;
std::cin >> MenuChoice;
if (MenuChoice == 1)
{
//
}
else if (MenuChoice == 2)
{
//
}
else
{
std::cout << "INVALID OPTION! ";
}
}
void CheckPassword()
{
std::cout << "Enter your current password : n";
std::cin.ignore();
std::cin >> UserPassword;
if (strlen(UserPassword) >= 10)
{
Length = strlen(UserPassword);
for (int i=0; i<Length; i++)
{
if (Length[i] == 'a' && Length[i] == 'z') ++LowerCaseAmount;
if (Length[i] == 'A' && Length[i] == 'Z') ++UpperCaseAmount;
if (Length[i] == '0' && Length[i] == '9') ++DigitAmount;
if (Length[i] == '!' && Length[i] == '*') ++SpecialCharAmount;
}
if (LowerCaseAmount > 0 && UpperCaseAmount > 0 && DigitAmount > 0 && SpecialCharAmount > 0)
{
std::cout << "Secure! ";
}
else if (LowerCaseAmount == 0)
{
std::cout << "Try adding some lower case letters! ";
}
else if (UpperCaseAmount == 0)
{
std::cout << "Try adding some upper case letters! ";
}
else if (DigitAmount == 0)
{
std::cout << "Try adding some numbers! ";
}
else if (SpecialCharAmount == 0)
{
std::cout << "Try adding some special characters! ForEX : @, $, % ";
}
}
else
{
std::cout << "Password should be ten digits or loner! "
<< std::endl;
}
}
};
int main()
{
return 0;
}
int Length;

您声明了一个int类成员Length

if (Length[i] == 'a' && Length[i] == 'z') 

这是使用Length,如果它是一个数组(或一些容器与[]过载)。Length不是数组。Length只是一个普通、无聊、孤独的int,见上文。这就是你的编译错误的原因。

查看整个代码,似乎您应该在这里查看userPassword,这是您的数组(或类数组)对象。

相关内容

  • 没有找到相关文章

最新更新