There is a code:

for (int i = 0; i < text.length(); ++i) { if(isalpha(rus_alphabet[_indexOfSymbol(text[i], rus_alphabet, rus_size)])) { count_of_symbols[_indexOfSymbol(text[i], rus_alphabet,rus_size)] += 1; } } 

If the element of the rus_alphabet array, with the index _indexOfSymbol(функция, которая возвращает индекс элемента) is a letter, then add 1. The problem is that isalpha works only for char, and I can’t convert string to char(не char* ) , to compare them. PS string stores one letter. I am comparing the whole string, not character by character. String is an element of an array of strings!

rus_alphabet has the following form: rus_alphabet[0] = "А";

Closed due to the fact that the question’s essence is not clear to the participants from Vlad from Moscow , αλεχολυτ , ermak0ff , user194374, Denis Bubnov 13 Feb '17 at 11:12 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Absolutely nothing is clear. What is the type of the rus_alphabet array element? - Vlad from Moscow
  • You're probably kidding. Well, I repeat: rus_alphabet has the following form: rus_alphabet [0] = "A"; - kot_mapku3
  • @rus_alphabet P Why are you then trying to apply the isalpha function to a string? And why not declare an array of rus_alphabet as a character array? Or do you create difficulties for yourself specifically so that you can successfully overcome them? - Vlad from Moscow
  • Because I do not know how it should be, therefore I ask, because isalpha applies to char . - kot_mapku3
  • one
    Try writing WHAT you need specifically. From what you wrote, you can guess what you need - whether the number of letters in a line, or something else. - Daniel Protopopov

1 answer 1

If the only question is how to get the first character from char from std::string , then you can:

 string s = "a"; char c1 = s.c_str()[0]; // так char c2 = *s.c_str(); // или так char c3 = s[0]; // вариант alexolut 
  • It does not work like that with Russian characters - kot_mapku3
  • one
    Std :: wstring and wchar_t will work with Russians instead of std :: string and char. Accordingly, you will need to use iswalpha instead of the usual isalpha - Daniel Protopopov
  • @DanielProtopopov a lot will change if I change the code to wstring? - kot_mapku3
  • Of course, a lot of it is because the usual char cannot accommodate Cyrillic, only English 8-bit characters. - Daniel Protopopov
  • 2
    Why is c_str here? You can just s[0] . - αλεχολυτ