【发布时间】:2016-09-23 18:58:43
【问题描述】:
在这个程序中,用户在命令行中输入两个字符串。其中一个是数字,另一个是字符串。该程序旨在根据电话拨号每个按钮上的数字/字母来检查输入的数字和字符串是否相等。我得到一个例外,上面写着:
Unhandled exception at 0x775DDAE8 in Project10.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0018F158.
任何帮助都非常感谢你:)
using namespace std;
bool checkPswd(string keyStrokes, string password) {
string temp;
string temp2;
bool temporary = 1;
string phoneButtons[10] = {
"", ""
"abc", "def", "ghi", "jkl",
"mno", "pqrs", "tuv", "wxyz"
};
for (int i = 0; i < keyStrokes.length(); i++) {
for (int j = 2; j < 10; j++) {
for (int k = 0; k < phoneButtons[j].length(); k++) {
temp = phoneButtons[j];
if (password.at(k) == temp.at(k)) {
temp2 = +(char)k;
}
else {
//do nothing
}
}
}
}
cout << temp2;
for (int m = 0; m < temp2.length(); m++) {
if (temp2.at(m) == keyStrokes.at(m)) {
//keep searching
}
else {
return 0;
}
}
return 1;
}
int main(int argc, char ** argv) {
if (argc != 3) {
cout << "Please input the key strokes from the phone and the password." << endl;
return 1;
}
string keyStrokes = argv[1];
string password = argv[2];
bool check;
check = checkPswd(keyStrokes, password);
if (check) {
cout << "Password Verified" << endl;
}
else {
cout << "Wrong Password" << endl;
}
return 0;
}
【问题讨论】:
标签: c++ exception indexoutofboundsexception