Algorithm of identification.

Task: when developing the identification and authentication mechanism, check the password (Russian and Latin letters should alternate in the password and its length should not exceed 15 characters).

My decision:

#include "LAB4.h" void main() { setlocale(LC_ALL, "RUSSIAN"); int choice = 0; while (choice != 2) { choice = menu(); switch (choice) { case 1: if (check_pass()) cout << "Пароль удовлетворяет условиям.\n"; else cout << "Пароль не удовлетворяет условиям!\n"; break; case 2: exit(0); break; default: break; } } return; } int menu() { cout << "Выберите нужный пункт меню.\n"; cout << "1.Проверить пароль\n"; cout << "2. Выход\n"; cout << "Ваш выбор: "; int ch = 0; cin >> ch; return ch; } bool check_pass() { string passEN = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; string passRU /*char *passEN */ = /*new char */ "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; int ctr = 0; cout << "Требования к паролю:\n1.Пароль должен содержать 12 символов.\n2.В пароле чередуются буквы и цифры.\n"; cout << "Введите пароль: "; string pass; cin >> pass; cout << "Длина пароля -> " << pass.length() << endl; int len = pass.length(); //длина пароля int lenEN = passEN.length(); //длина англ алфавита int lenRU = passRU.length(); //длина рус алфавита if (len <= 15) for (int i = 0; i < lenRU; i++) { if ((isalpha(passRU[i]) && isalpha(passEN[i + 1])) || (isalpha(passEN[i]) && isalpha(passRU[i + 1]))) { ctr = ctr + 1; } if (ctr == len) return true; } return false; } 

Gives an error message:

1>error C2678: бинарный ">>": не найден оператор, принимающий левый операнд типа "std::istream" (или приемлемое преобразование отсутствует)

File h code:

 #include <iostream> #include <clocale> #include <stdio.h> #include <string.h> using namespace std; int menu(); bool check_pass(); 

Why the error comes out and how to get rid of it to make it work.

  • <string.h> ? - VladD
  • Specify the compiler, in gcc 4.7 this problem does not arise - Dith

1 answer 1

operator >> is not overloaded for istream and string, only for C-lines (char *). Use better getline and, if necessary, check for spaces in the resulting line.

Are you sure that isalpha works for Cyrillic? Not really. You need to use wstring, wchar_t and functions to work with them (see the cwchar header). In addition, you have to get the string wstring from wcin and work with it already. Tip: first, work out the program only in Latin and only then go to Cyrillic.