#include <iostream> #include <cstring> using namespace std; void searchCenzur() { char str[80] = "lsasacsalolcassalolasclolcascaslol"; int j = 0; for(int i = 0; i < 80; i++) { if(str[i] == "l") { if(str[i+1] == "o") { if(str[i+2] == "l") { j++; } } } } cout << "количество совпадений: " << j << endl; } int main() { searchCenzur(); return 0; } 

error main.cpp: 14: 27: error: ISO C ++ forbids comparison between pointer and integer [-fpermissive]

  • one
    str[i] is a character. "l" is a string. - VladD September
  • one
    Single characters are encoded with single quotes (apostrophes) - like this 'a' , not "a" (this is how they write strings that are represented in memory by a sequence of characters ending in binary zero) - avp

1 answer 1

So it will be right:

 #include <iostream> #include <cstring> using namespace std; void searchCenzur() { char str[80] = "lsasacsalolcassalolasclolcascaslol"; int j = 0; for (int i = 0; i < 80; i++) { if (str[i] == 'l') { if (str[i + 1] == 'o') { if (str[i + 2] == 'l') { j++; } } } } cout << "количество совпадений: " << j << endl; } int main() { searchCenzur(); return 0; } 
 if (str[i] == "l") 

You compare one character with a string (character set), in c ++ it is not possible, only a character with a character and in one encoding.

UPD:

Judging by the code, you need to find the number of matches of the substrings in the string - if you wanted to solve this particular problem, then a ready-made solution in the next topic .

  • how to organize the check normal then? )) - Ugnius Mkrthcan
  • @Ugnius Mkrthcan, I gave the correct sample code in my answer, if you need to find something else, then describe what exactly you want to do, otherwise I will not be able to help you. - Duracell