Home c++ Compilation error: error: ISO C++ forbids comparison between pointer and integer

Compilation error: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

Author

Date

Category

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


Answer 1, authority 100%

This will be correct:

# include & lt; iostream & gt;
#include & lt; cstring & gt;
using namespace std;
  void searchCenzur ()
  {
    char str [80] = "lsasacsalolcassalolasclolcascaslol";
    int j = 0;
    for (int i = 0; i & lt; 80; i ++)
    {
      if (str [i] == 'l')
      {
        if (str [i + 1] == 'o')
        {
          if (str [i + 2] == 'l')
          {
            j ++;
          }
        }
      }
    }
    cout & lt; & lt; "number of matches:" & lt; & lt; j & lt; & lt; endl;
  }
  int main ()
  {
    searchCenzur ();
    return 0;
  }
if (str [i] == "l")

You are comparing one character with a string (character set), in C++ this is not possible, only a character with a character and in the same encoding.

UPD:

Judging by the code, you need to find the number of substring matches in the string – if you wanted to solve this particular problem, then out-of-the-box solution in a neighboring topic .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions